Well, it sounds like the frame rate goes down intermittently because
of the garbage collector.

First of all, you should not be doing any object creation during your
game loop.  This way there is never any need for a GC.
1. Create all of your objects before hand.  For example,
Monster[] mMonsters = new Monster[Monster.MAX];
setup() {
 for (int i = 0; i < mMonsters.length; i++) {
  mMonsters[i] = new Monster();
  mMonsters[i].used = false;
 }
 ...
}
Instead of creating a new monster every time one comes into play, just
set its used flag to true (and set it to false, instead of deleting
it, when the monster is done).

2. Use android.os.SystemClock.uptimeMillis() when limiting your FPS.
Basically what you want to do is keep track of each game tick, and if
it hasn't been 1/30 seconds yet, sleep for the remaining time.

3. Google "java game optimization".

-Matt

On Jul 22, 3:46 pm, Cameron <cameron.m.john...@gmail.com> wrote:
> I based my game off of the lunar lander demo, although heavily
> modified, and I can get around 40-50fps but the problem is it
> fluctuates between 40-50fps so much that it causes the moving graphics
> to jitter! Its very annoying and makes my game look really shitty when
> in fact its running at a good frame rate.
>
> I tried setting the thread priority higher but that just made it
> worse... now it will fluctuate between 40-60fps...
>
> I was thinking of limiting the FPS to about 30 so that it will be
> constant. Is this a good idea and does anyone else have experience or
> a different solution?
>
> Thanks!
>
> PS: If you have an example of limiting or creating constant FPS that
> would be helpful. I've tried it before but never got it quite right.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to