No one will tell you how to make the image rotate on java? Wanted to use

canvas.save(); canvas.rotate(angle); canvas.drawBitmap(player, x, y, null); canvas.restore(); 

but somehow it doesn’t react so well. I need the image to rotate constantly.

UPDATE:

Found a working example

 class Car { final Matrix transform = new Matrix(); final Bitmap image; Car(Bitmap sprite) { image = sprite; // Created by BitmapFactory.decodeResource in SurfaceView } void update() { this.transform.preRotate(turnDegrees, width, height); } void display(Canvas canvas) { canvas.drawBitmap(this.image, this.transform, null); } } 

but it turns very dumb, not around its axis, but around the axis of the devil knows what)

  • one
    that constantly - you need a stream =) depending on your task, if there is just a picture - loading - I would use gif-ku =) - Gorets
  • I do not want to use sprites, but in my case I write for android, there are no gifs, current sprites ... - dajver
  • oh people! could you tell me pliz - dajver

1 answer 1

If the animation is done for Android, then you can try the View Animation

You can use the system. Tween animation calculates the angles of the animation.

Rotation of the canvas can be done like this:

 Matrix m = new Matrix(); m.setTranslate(centerX, centerY); m.preRotate(angle, width/2, height/2); canvas.drawBitmap(bitmap, m, null); 
  • How to make the picture spin? This method only rotates but does not animate. - dajver
  • one
    To rotate (animate) smoothly, you need to rotate a small angle every T milliseconds. - andrybak