2015-10-14 102 views
0

我尝试在Android中制作旋转游戏的游戏。 我发现很难以正确的方式旋转圆圈。 我很想帮助如何旋转圆圈并停止它,以便每次都得到不同的结果。 目前它已经确定了一定的时间并返回到开头。 如果我通过这个msmallWheelBack.clearAnimation()停在它的中间,它将返回到一轮的开始。 非常感谢您的帮助。轮盘赌动漫旋转得到它停止的位置Android

在我的代码:

Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_around_center_point); 
    mframeWheelBig.startAnimation(animation); 

的动画XML:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:shareInterpolator="false" > 
<rotate 
    android:duration="2500" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:repeatCount="infinite" 
    android:toDegrees="360" 
    android:fromDegrees="0" 
    android:fillAfter="true" 
    android:fillBefore="true" 
    android:fillEnabled="true"/> 
</set> 

就像我说的,这是我如何停止动画

mframeWheelBig.clearAnimation(); 

回答

0

您可以编程设置一个随机'toDegrees'的值。我想你也可以设置超过360度,以获得更多的旋转。

但是,我没有找到该值的setter方法,所以我想你将不得不以编程方式创建动画,使用RotateAnimation,但仍然应该很容易。

这将在3到6转之间旋转,并可以停在任何角度。

final static int MIN_TURNS = 3; 
final static int MORE_TURNS = 3; 
float toDegrees = 360 * MIN_TURNS + Math.random() * 360f * MORE_TURNS; 
Animation anim = new RotateAnimation(0, toDegrees); 
+0

的一个大问题是,它在阻止它开始 – gal

+0

动画停止在它开始的地方的地方,因为你所定义的360度,这正好是一个完整的转身结束位置。通过为结束位置提供随机值,这不会发生。 – Ridcully

+0

int MIN_TURNS = 3; int MORE_TURNS = 3; float toDegrees = 360 * MIN_TURNS +(float)Math.random()* 360f * MORE_TURNS; Log.i(“toDegrees”,“”+ toDegrees);动画动画= new RotateAnimation(0,toDegrees,200,200); animation.setInterpolator(new AccelerateDecelerateInterpolator()); animation.setDuration(1000); animation.setFillAfter(true); – gal