views:

31

answers:

1

To better explain this I'll use Doodle Jump as an example. Assuming that the platforms are recycled, when the character jumps up and the new platforms appear (by scrolling down) there is occasionally a propeller hat on one of them. is there a recommended method to manage this new object? Should I instantiate a single one of these power-ups in the game level's "init" method, and then set a boolean to flag whether it appears in my render method and update methods? Or should I instantiate it at the time that I want it to appear (i.e. just before the new platform scrolls down from its position just above the screen) and release it when it's a) grabbed by the character sprite or b) moves off the screen untouched?

Thanks!

  • Scott
+1  A: 

I vote for the latter - instantiate it at the time you want it to appear. If you use some flag to determine whether to display it or not, you'll end up with a bunch of special-case code; not something you want, especially for something this relatively simple.

Considering that you're developing for a mobile device, if for some reason the construction of this object is effecting performance, then I would look into alternate methods (i.e., instantiate once, use flag to render/update).

Shakedown