1

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.

rint
  • 255
  • 1
  • 3
  • 10

1 Answers1

0

Some think like this:

Bitmap image;
Matrix m;
.
.
.
public YourClass(){
    m = new Matrix();
    image = Bitmap.createBitmap(image, 0, 0, width, height,);
}
.
.
.
public void mainGameLoop(Canvas c){
    m.setRotate(angle, imageCenterX, imageCenterY);
    yourCanvas.drawBitmap(image, m, null);
}
Piotr Golinski
  • 990
  • 8
  • 19