简体   繁体   English

平滑位图旋转android SurfaceView

[英]Smooth bitmap rotation android SurfaceView

I'd like to make my asteroids rotate constatly in my android game but I have completely no idea where to start. 我想让小行星在我的Android游戏中恒定旋转,但我完全不知道从哪里开始。

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? 我的意思是我只在90度,180度,270度时才知道,您能帮我一下吗? I just need a hint. 我只需要一个提示。

Thanks for you help! 感谢您的帮助!

EDIT: I finally figured it out just with canvas.rotate() 编辑:我终于想通了canvas.rotate()

You can use the built-in android.R.anim.linear_interpolator from your animation XML file with android:interpolator="@android:anim/linear_interpolator" 您可以将动画XML文件中的内置android.R.anim.linear_interpolatorandroid: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 : 使用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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM