Game objects & sprites: has-a or is-a?

Started by
13 comments, last by lucky_monkey 19 years, 2 months ago
Quote:Original post by EDI
well it all depends in how you define a 'sprite'

as far as we are concerned, a sprite is a single object in the game world, a character an item, etc.

and any sprite has the ability to be animated or moved, etc.

a sprite need not have an image associated with them,

or a sprite can have it's drawing overriden to allow for a more complex system of images or effects to be performened (a derived sprite) for particles and such.

again, it's all in how you define 'sprite'

so i dont think it is as 'matter of fact' as you say =)

if you define a sprite as being, the actual image data for a game object,
then yes that image data should be 'shared' via is has-a type system.

however, we define a sprite as being, the game object itself, and our image data comes from an ImageSet object.


I think EDI summed it up nicely here. Unless there is an absolute definition for "sprite" somewhere (a game programmers dictionary?) it is going to depend on your own situation. If a sprite is defined as the image data then I think most people here agree it 'has-a' sprite and if a sprite is defined as an actual tangeable object then it is 'is-a' sprite. Luckily for us I don't think there really is a game programmers dictionary so our life is filled with mystery :).
Evillive2
Advertisement
How I'm working my sprites, is I have an object that is a SpriteCache, and it contains groupings of sprites by a key.
SpriteCache["Sprite_Cache_Key"] = image;
Tis way in each of my Actor objects they just have a String that is the Sprite_Cache_Key that the object has for a sprite.

So some code would be like (in java):
public void drawTile(int cX, int cY, Graphics2D g, Sprite_Cache s, int y, int x) {		if (y % 2 == 0) {			g.drawImage((Image)s.getImage(((Tile)tiles[y][x]).cSck), 40*x   +cX, 10*y-(((Tile)tiles[y][x]).height)*8+cY, null);		} else {			g.drawImage((Image)s.getImage(((Tile)tiles[y][x]).cSck), 40*x+20+cX, 10*y-(((Tile)tiles[y][x]).height)*8+cY, null);		}	}//tiles[y][x] = tile tracking array


Is this a completely bad way to do it?
BRING BACK THE BLACK (or at least something darker)
Quote:Original post by H_o_p_s


Is this a completely bad way to do it?


I'm no expert, so the only advice I can give is to use a number for the key. It should be faster [comparing 1-4 bytes, rather than an arbitrary sized string] (assuming java isn't smart enough to optimize the strings out for you).
I never even thought of that.... hmmm... maybe I can pump out a few more frames by switching over :)
BRING BACK THE BLACK (or at least something darker)
I have to say that the word sprite has graphical connotations for me...(I'd use has-a). In terms of actual definitions, it also seems to be the consensus.

In reality though I don't think your personal definition matters as long as it doesn't cause confusion...(and it's not too different from mine [evil])

This topic is closed to new replies.

Advertisement