Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am writing 2D side scrolling bullet hell-like game. I am at a point where I struggle to pull off smooth fps. I have separated loop that manages drawing.

However I want update the position of sprites from game logic(for bullets). Since there are many bullets, waiting for new set of position significantly decreases the speed in which the drawing loop executes itself.

I thought about another approach like this:

I could upload and stack positions of bullets somewhere. So my drawing method can pull off only the previously completely uploaded data, but doing so it can free itself from worrying about waiting for updating since stacked data is already in there. however <- that approach seems counter intuitive.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

I read from a book (the book is "Starting android game development") that the Garbage collector is your worst enemy at the moment of making a game. That's because it takes time of it's own to recycle objects.

So try to reuse your bullet instances instead of trashing them. That way you will not necessarily run out of memory. Also try to keep a static count on bullets and fix a max number of them. If you use some kind of list you can even stack them for recycling.

share|improve this answer
    
The easiest way to check for GC-induced problems is to watch the logcat output. If you see a lot of GC messages from Dalvik, you need to find a way to reduce object churn. (These are logged at "debug" level.) –  fadden Jun 18 '13 at 0:10
add comment

The idea you describe is sound. See Replica Island for an example of a game that generates "draw lists" in one thread, and renders them from a GLSurfaceView draw callback.

The only tricky part is to make sure that keep the lock held for as little time as possible, so you don't stall the renderer. Since your game state updates are expensive, you'll want to do the slow updates into a "private" data structure, then grab the lock, update the draw list, and release the lock.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.