Actions are one of the ways to add life to your game and make things
interactive. Actions allow you to perform different things such as moving,
rotating, or scaling nodes, playing sounds, and even running your custom code.
When the scene processes its nodes, actions that are linked to these nodes are
executed.
To create a node, you run a class method on an action that you need, set
its properties, and call the runAction: method on your node with action as a
parameter.
There are different action types; here we will list some of them.
- moveTo(duration:) This
particular constructor returns an action that moves a sprite to a
specified position over a specified duration (in seconds).
- moveToX(duration:) and moveToY(duration:).
These allow you to specify a change in only the x- or y-position; the
other is assumed to remain the same.
- moveByX(y:duration:) The “move to”
actions move the sprite to a particular point, but sometimes it’s convenient
to move a sprite as an offset from its current position, wherever that may
be.
- removeAllActions() All actions are removed from the node
immediately. If a removed action had a duration, any changes it already
made to the node remain intact, but further changes are not executed.
- runAction(_ action: SKAction, completion block: (() -> Void)!) method is identical to
the runACtion: method,
but after the action completes, your block is called. This callback is
only called if the action runs to completion. If the action is removed
before it completes, the completion handler is never called.runAction:withKey: method
to run the action. If an action with the same key is already executing, it
is removed before the new action is added.
- runAction:withKey method
to run the action. If an action with the same key is already executing, it
is removed before the new action is added.
- actionForKey: method to determine if an action with
that key is already running.
- removeActionForKey: method to remove the action.
- A sequence
action (or sequence) has multiple child actions. Each
action in the sequence begins after the previous action ends.
- A group
action(or group) has multiple child actions. All actions
stored in the group begin executing at the same time.
- A repeating
action has a single child action. When the child action
completes, it is restarted.
CEO, Meteora Gaming
Very Interesting Topic in iOS Gaming...
ReplyDelete