CCActionSpeed Class Reference
Inherits from | CCAction : NSObject |
---|---|
Conforms to | NSCopying |
Declared in | CCAction.h |
Overview
Allows you to change the speed of an action while the action is running. Useful to simulate slow motion or fast forward effects. Can also be used to implement custom easing effects without having to create your own CCActionEase subclass.
You will need to keep a reference to the speed action in order to change its speed
property. It is best to assign
the speed action to an ivar or property with the __weak
(ivar) or weak
(@property) keyword.
For instance:
@implementation YourClass
{
__weak CCActionSpeed* _speed;
}
Now you can create an action whose speed you want to be able to alter while the action is running:
id move = [CCMoveBy actionWithDuration:60 position:ccp(600, 0)];
_speed = [CCActionSpeed actionWithAction:move speed:1];
The speed factor of 1 will start running the move
action at its normal speed. Later when you determined that it’s
time to change the speed of the move
action, just change the _speed
action’s speed
property:
-(void) update:(CCTime)deltaTime
{
if (slowMotionMode) {
_speed.speed = 0.2f; // move at one fifth of the regular speed
} else {
_speed.speed = 1.0f; // move at regular speed
}
}
When the move action has run to completion it will end and thanks to the __weak
keyword and ARC the _speed
ivar will
automatically become nil
.
Note: CCActionSpeed can not be added to a CCActionSequence because it does not inherit from CCActionFiniteTime. It can however be used to control the speed of an entire CCActionSequence.
Creating a Speed Action
Modifying Speed
speed
Alter the speed of the controlled action at runtime.
@property (nonatomic, readwrite) CGFloat speed
Discussion
- Speeds below 1.0 will make the action run slower.
- Speeds above 1.0 will make the action run faster.
Declared In
CCAction.h