On Fri, Apr 2, 2010 at 5:58 PM, Matthew Patience <
[email protected]> wrote:
> What I want to do is while the user is
> holding down the fire button to have it keep creating instances of the
> Laser class like a rapid fire and then when they hit the edge of the
> screen have them be disappear/destroyed so they are no longer taking
> up memory.
>
To add to what has been said, you probably don't want to be continuously
creating / destroying these laser objects if they are going to be used in
high-frequency - and it sound like they are ("rapid fire"). This would mean
a lot of unnecessary memory allocation and de-allocation that is likely to
hurt your performance on a mobile device.
Instead you could have a small pool of Laser objects initialized up front
that will be the max number of lasers the user can fire and see on screen at
any given time. By default all objects are "inactive", or "unfired". When
the user fires one, you find the first inactive laser and "fire" it, which
means making it active and getting it ready to move along it's path. Once
it's hit something or is off screen, it's marked inactive again
("destroyed") to be put back in the pool for re-use.
You could do this with two lists (active and inactive), moving items back
and forth as necessary, or with one list and setting a flag on each laser
object indicating it's current state.
Just some stuff to think about as you make your game. Hope that helps! Good
luck!
-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe, reply using "remove me" as the subject.