Should actors in a game be responsible for drawing themselves?
Posted
by
alex
on Game Development
See other posts from Game Development
or by alex
Published on 2011-06-25T01:33:07Z
Indexed on
2011/06/25
8:31 UTC
Read the original article
Hit count: 284
I am very new to game development, but not to programming.
I am (again) playing around with a Pong type game using JavaScript's canvas
element.
I have created a Paddle
object which has the following properties...
width
height
x
y
colour
I also have a Pong
object which has properties such as...
width
height
backgroundColour
draw()
.
The draw()
method currently is resetting the canvas
and that is where a question came up.
Should the Paddle
object have a draw()
method responsible for its drawing, or should the draw()
of the Pong
object be responsible for drawing its actors (I assume that is the correct term, please correct me if I'm incorrect).
I figured that it would be advantagous for the Paddle
to draw itself, as I instantiate two objects, Player
and Enemy
. If it were not in the Pong
's draw()
, I'd need to write similar code twice.
What is the best practice here?
Thanks.
© Game Development or respective owner