1
votes

I'd like to make my asteroids rotate constatly in my android game but I have completely no idea where to start.

I know I can rotate canvas, but I can't find a mathematical formula where to draw the object after the canvas is rotated by any angle, so that it is where it should be after I restore canvas.

I mean I figured it out only for 90, 180, 270 degrees, can you help me a bit? I just need a hint.

Thanks for you help!

EDIT: I finally figured it out just with canvas.rotate()

1
use a Matrix API for example Matrix.mapPointspskink

1 Answers

0
votes

You can use the built-in android.R.anim.linear_interpolator from your animation XML file with android:interpolator="@android:anim/linear_interpolator"

you can use it something like this:

<?xml version="1.0" encoding="UTF-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toDegrees="359" />

Using java :

//Rotate Asteroids
ImageView mAsteroids = (ImageView) findViewById(R.Id.Asteroids);
mAsteroids.setDrawingCacheEnabled(true);
rAnim = new RotateAnimation(0.0F, 359.0F, Dimension.RelativeToSelf, 0.5F, Dimension.RelativeToSelf, 0.5F);  
rAnim.Interpolator = new LinearInterpolator();
rAnim.RepeatCount = Animation.Infinite;
rAnim.Duration = 1500; //<-- you duration
mAsteroids.StartAnimation(rAnim);