菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
35
0

SKAction

原创
05/13 14:22
阅读数 2571

[SKAction]

 1、Every action is an opaque object that describes a change you want to make to the scene. All actions are implemented by the SKAction class; there are no visible subclasses. 

 2、Actions can either be instantaneous or non-instantaneous:

  • An instantaneous action starts and completes in a single frame of animation. For example, an action to remove a node from its parent is an instantaneous action because a node can’t be partially removed. Instead, when the action executes, the node is removed immediately.

  • A non-instantaneous action has a duration over which it animates its effects. When executed, the action is processed in each frame of animation until the action completes.

 3、Tip: Because actions are effectively immutable objects, you can run the same action safely on multiple nodes in the tree at the same time. For this reason, if you have an action that is used repeatedly in your game, create a single instance of the action and then reuse it whenever you need a node to execute it.

 4、If a node is running any actions, its hasActions property returns YES.

 5、Because action processing is tied to the scene, actions are processed only when the node is part of a presented scene’s node tree. You can take advantage of this feature by creating a node and assigning actions to it, but waiting until later to add the node to the scene. Later, when the node is added to the scene, it begins executing its actions immediately.

 6、Canceling Running Actions

  To cancel actions that a node is running, call its removeAllActions method. 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.

 7、Receiving a Callback when an Action Completes

  The runAction:completion: 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.

 8、Using Named Actions for Precise Control over Actions

  If you need to see whether a particular action is executing or remove a specific action, you must use named actions.

  The following key-based methods are available: 

  • 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.

 9、Repeating Actions Execute Another Action Multiple Times

  

  

 10、Configuring Action Timing

  • Normally, an animated action runs linearly. You can use an action’s timingMode property to choose a nonlinear timing mode for an animation. For example, you can have the action start quickly and then slow down over the remainder of the run.

  • An action’s speed property changes the rate at which an animation plays. You can speed up or slow down an animation from its default timing.

    A speed value of 1.0 is the normal rate. If you set an action’s speed property to 2.0, when the action is executed by a node, it plays twice as fast. To pause the action, set the value to 0.

    If you adjust the speed of an action that contains other actions (such as a group, sequence, or repeating action), the rate is applied to the actions contained within. The enclosed actions are also affected by their own speed property.

  • A node’s speed property has the same effect as the action’s speed property, but the rate is applied to all actions processed by the node or by any of the node’s descendants in the scene tree.

  Sprite Kit determines the rate at which an animation applies by finding all of the rates that apply to the action and multiplying them.

 11、Tips for Working with Actions   

  following tips might be useful:

  • A node’s userData property

  • The parent node’s userData property, if dozens of nodes share the same actions and the same parent

  • The scene’s userData property for actions shared by multiple nodes throughout the scene

  

 

 

 

发表评论

0/200
35 点赞
0 评论
收藏