Best practice: adding variables to display objects?

I'm working on a game. I create about 40 game sprites and need to keep track of action states and other information for each. Seems I have two options to work with all of this.

1) Assign variables to each of the sprite objects created. Something like

local invader = sprite.newSprite( invader_spritesheet )
invader.is_hit = false
invader.row = row
invader.col = col
etc.

Or method 2) Create an array or table to hold a reference to the display object and hold properties describing the game state of that display object.

At the moment I'm using the second method using display object as the property for each table element. Which seems to work fine.

This is more a matter of personal preference, but I add properties to the display objects, since they are effectively Lua tables. I don't see a need to create another table to store data when I've already created one (the display object).

Thanks,
Darren

Thanks for the reply. It is more convenient to use the display object to hold it's own properties in many cases. I just worry about getting into bad habits.

As was said, it's just personal preference :)

views:1524 update:2011/12/31 9:35:10
corona forums © 2003-2011