Advertisement

Sprite-Player Relationship

Started by February 24, 2003 01:26 AM
4 comments, last by Punx 21 years, 8 months ago
For my game I have a Player class which holds all player data and a Sprite class which is the representation of that on screen. Should the relationship between these two classes be a is-a or has-a? Should the player be a sprite or have a sprite? [edited by - punx on February 24, 2003 2:26:53 AM]
~punx
I would imagine this would depend on your game. For example, If you supporting multiple players with different images, then have the player class hold a sprite member. However, if its the same image, then why add it in the player class? Just reference it directly when displaying it.
<=- Talon -=>
Advertisement
I''d say that you should have a CSprite member of the CPlayer class.

so CPlayer has a CSprite...

but that''s only the way i''d do it.
Programmers of the world, UNTIE!
I would go for containment and make your sprite a member of your player.

"Discipline is never an end itself, only a means to an end." - Robert Fripp
"Discipline is never an end itself, only a means to an end." - Robert Fripp
Nice to see some people suggest this, as it was what I have planned for a game I hope to write in the near future. I chose this method (has-a) because the player likely needs things other than just a sprite (health, speed, etc...) which is more than just a simple sprite.

Peon
Peon
Has sprite always. Simply because sometimes your player will want 2 or more sprites, especially when those multiple graphical effects come into play.

This topic is closed to new replies.

Advertisement