samedi 25 avril 2015

Rotating bitmap in main game loop without overloading GC in Android


What is the correct way to rotate bitmap every frame in main game loop? What I have tried:

I created rotated bitmap every frame:

Bitmap image, tmp;
Matrix m;
...
public void mainGameLoop(Canvas c){
    m.reset();
    m.postRotate(angle);
    tmp = Bitmap.createBitmap(image, 0, 0, width, height, m, true);
    c.drawBitmap(tmp, 50, 50, null);
}

However, because Bitmap.createBitmap creates bitmap every frame Garbage Collector works so madly, it causes low FPS.

I have tried saving bitmap in array at all angles, and just taking bitmap which I want to. However, this needs a lot of RAM and app just couldn't launch at high screen resolutions.

If you have any ideas, please comment below.


Aucun commentaire:

Enregistrer un commentaire