Answer: Brad Larson
(Best answer)
I don't know how to insert animations on cocos2d, but you can create core animations with CALayers or UIViews. Perhaps the simplest way is to create a UIImageView containing * patterns and then animate it.
First, create a new UIImageView and set the * pattern to its initial value. If you want the * to rotate, use the following code:
Assume rotatingImage is the UIImageView you need.
In this example, the turntable will rotate 5 times, each time taking 0.5 seconds. The rotation will stop at half a circle, because Core Animation changes direction at half a circle, so before the rotation changes direction, at most Let the turntable turn half a turn. In other words, if you set the rotation angle to (1.5f * pi), it can only rotate ninety degrees. If you set the radian value to (0.999f * pi), the turntable will rotate clockwise.
If you want to achieve acceleration or deceleration effects, it is best not to use CABasicAnimation. CAKeyframeAnimation will have better effects.
Complete the rotation action. If you need continuous rotation, you can set it
id action = [RepeatForever actionWithAction: [RotateBy actionWithDuration:dur angle:360]];
[sprite runAction:action];
and
[sprite stopAction:action];
Before this, be sure to set the sprite transformAnchor so that the image is centered.
Answer: mahboudz
You can set different arc parameters to complete a complete rotation, without having to consider whether it can complete a complete rotation, and there is no need to divide the entire rotation process into several parts to design. For example, the following code can complete the rotation effect, rotating once per second:
Answer: EightyEight
There are many ways to achieve animation effects. If you want to set a frame-by-frame mode animation effect for the turntable, you can use AtlasDemo to achieve this goal.
Answer: Brad Larson
(Best answer)
I don't know how to insert animations on cocos2d, but you can create core animations with CALayers or UIViews. Perhaps the simplest way is to create a UIImageView containing * patterns and then animate it.
First, create a new UIImageView and set the * pattern to its initial value. If you want the * to rotate, use the following code:
Assume rotatingImage is the UIImageView you need.
In this example, the turntable will rotate 5 times, each time taking 0.5 seconds. The rotation will stop at half a circle, because Core Animation changes direction at half a circle, so before the rotation changes direction, at most Let the turntable turn half a turn. In other words, if you set the rotation angle to (1.5f * pi), it can only rotate ninety degrees. If you set the radian value to (0.999f * pi), the turntable will rotate clockwise.
If you want to achieve acceleration or deceleration effects, it is best not to use CABasicAnimation. CAKeyframeAnimation will have better effects.
Answer: Stanislav
In cocos2d, an easy way is: set
Complete the rotation action. If you need continuous rotation, you can set it
and
Before this, be sure to set the sprite transformAnchor so that the image is centered.
Answer: mahboudz
You can set different arc parameters to complete a complete rotation, without having to consider whether it can complete a complete rotation, and there is no need to divide the entire rotation process into several parts to design. For example, the following code can complete the rotation effect, rotating once per second:
Answer: EightyEight
There are many ways to achieve animation effects. If you want to set a frame-by-frame mode animation effect for the turntable, you can use AtlasDemo to achieve this goal.