I've currently been working on a game where a ship has the ability to shoot enemies as they come down the screen. I spawn enemies that are views at a certain interval and track their position as they move down the screen. The same is true with the bullets the ship fires. Each bullet is a view and it tracks it's position as it moves up screen. Obviously when they collide the enemie and bullet views are removed from te window. The trouble I'm having is that if there are a couple enemies on screen and I'm shooting at them the app will lag. And if I let the enemies continue to spawn (they get removed if they make it all the way down the page) the spawn rate will start to get faster. It's set to spawn an enemy every so many seconds and since the enemies are moving slower I end up with about a million on screen after a minute and snail snow speeds. Are there any tips or tricks to creating this kind of scenario? Perhaps not using views somehow? I'm using a set interval on each enemy because you can't track the position of a view as it's animating so could that be what's bogging it down? Any insigt at all into how to speed this up would be greatly appreciated.
That said, a few simple tips would be:
- cache the views/images as much as possible.
- minimize your calls to createView() by reusing objects. Allocations of any sort are slow.
- Use as few timers and event callbacks as possible.
You should use Ti modules, like GL (as Jeremy said) or box 2D...
Another trick is to simplify objects... A view witha background is better than an imageview in a view...
Think you can help? Login to answer this question!