首页 > 代码库 > CCAction Class 和 CCActionInterval Class 和 CCActionMoveTo Class ---Cocos2D-Swift v3.3

CCAction Class 和 CCActionInterval Class 和 CCActionMoveTo Class ---Cocos2D-Swift v3.3

CCAction Class Reference

Inherits fromNSObject
Conforms toNSCopying
Declared inCCAction.h

Overview

CCAction is an abstract base class for all actions. Actions animate nodes by manipulating node properties over time such as position, rotation, scale and opacity.

CCaction是一个关于所有动作的基本类型。通过操纵node属性,比如位置,旋转,透明度,规模等,激活Nodes。

 

For more information see the Concepts:Actions article in the Developer Guide

Subclasses

The following actions inherit directly from CCAction and can be used “as is”:

  • CCActionFollow (parent node follows the target node’s movement)
  • CCActionRepeatForever (runs a CCActionInterval in an endless loop until stopped)
  • CCActionSpeed (modifies the speed of a CCActionInterval action while it is running)

These action subclasses are abstract base classes for instant and “over time” actions, see their references for more information:

  • CCActionFiniteTime
    • CCActionInstant
    • CCActionInterval

Tasks

Creating an Action

  • + action
  • – init

Action Targets

  •   target property
  •   originalTarget property

Identifying an Action

  •   tag property

Action Methods Implemented by Subclasses

  • – isDone
  • – startWithTarget:
  • – stop
  • – step:
  • – update:

Properties

originalTarget

The original target, since target can be nil.

原始目标,可以为nil。

@property (nonatomic, readonly, unsafe_unretained) id originalTarget

Declared In

CCAction.h

tag

The action tag. An identifier of the action.

动作标签,定义一个动作.

@property (nonatomic, readwrite, assign) NSInteger tag

Declared In

CCAction.h

target

The “target” is typically the node instance that received the [CCNode runAction:] message. The action will modify the target properties. The target will be set with the ‘startWithTarget’ method. When the ‘stop’ method is called, target will be set to nil.

"target”是典型的node实例,可以接收[CCNode runAction:] 方法。acition会定义target属性。target可以通过startWithTarget方法设置,当stop方法被调用时,target会被置为nil。

@property (nonatomic, readonly, unsafe_unretained) id target

Discussion

Warning: The target is ‘assigned’ (unsafe unretained), it is not ‘retained’ nor managed by ARC.

Declared In

CCAction.h

Class Methods

action

Creates and returns an action.

创建和返回一个action

+ (id)action

Return Value

The CCAction Object.

Discussion

Warning: If a CCAction subclass provides designated initializers you will have to use those over this one.

Declared In

CCAction.h

Instance Methods

init

Initializes and returns an action object.

初始化和返回一个action对象。

- (id)init

Return Value

An initialized CCAction Object.

Declared In

CCAction.h

isDone

Return YES if the action has finished.

如果action结束,返回YES。
- (BOOL)isDone

Return Value

Action completion status

动作完成状态。

Declared In

CCAction.h

startWithTarget:

Assigns a target to the action Called before the action is started.

分配一个target给action。这回在action开始之前被调用。

- (void)startWithTarget:(id)target

Parameters

target

Target to assign to action (weak reference).

Declared In

CCAction.h

step:

Steps the action. Called for every frame with step interval.

action的步骤。每一帧被调用,步骤间隔。

- (void)step:(CCTime)dt

Parameters

dt

Ellapsed interval since last step.

Discussion

Note: Do not override unless you know what you are doing.

Declared In

CCAction.h

stop

Stops the action Called after the action has finished. Will assign the internal target reference to nil. Note: You should never call this method directly. In stead use: [target stopAction:action]

停止一个action,action结束后被调用。会让内部的target置为nil。

你永远不应该直接调用这个方法。用[target stopAction:action]代替。

- (void)stop

Declared In

CCAction.h

update:

Updates the action with normalized value.

用规范化的值更新动作。

- (void)update:(CCTime)time

Parameters

time

Normalized action progress.

Discussion

For example: A value of 0.5 indicates that the action is 50% complete.

Declared In

CCAction.h
 
 
 
 
 

CCActionInterval Class Reference

Inherits fromCCActionFiniteTime : CCAction : NSObject
Conforms toNSCopying
Declared inCCActionInterval.h

Overview

Abstract base class for interval actions. An interval action is an action that performs its task over a certain period of time.

关于间隔动作的抽象基本类。一个间隔动作是指一个动作在一段时间内完成整个过程。

Most CCActionInterval actions can be reversed or have their speed altered via the CCActionSpeed action.

大部分的CCActionInterval动作可以被逆转或者改变速率,通过CCActionSpeed动作。

Moving, Rotating, Scaling a Node

  • Moving a node along a straight line or curve:
    • CCActionMoveBy, CCActionMoveTo
    • CCActionBezierBy, CCActionBezierTo
    • CCActionCardinalSplineTo, CCActionCardinalSplineBy
    • CCActionCatmullRomBy, CCActionCatmullRomTo
  • Rotating a node:
    • CCActionRotateBy, CCActionRotateTo
  • Scaling a node:
    • CCActionScaleTo, CCActionScaleBy

Animating a Node’s Visual Properties

  • Periodically toggle visible property on/off:
    • CCActionBlink
  • Fading a node in/out/to:
    • CCActionFadeIn, CCActionFadeOut
    • CCActionFadeTo
  • Colorizing a node:
    • CCActionTintBy, CCActionTintTo
  • Skewing a node:
    • CCActionSkewTo, CCActionSkewBy
  • Animate the sprite frames of a CCSprite with CCAnimation:
    • CCActionAnimate
  • Animating a CCProgressNode:
    • CCActionProgressFromTo, CCActionProgressTo

Repeating and Reversing Actions

  • Repeating an action a specific number of times:
    • CCActionRepeat
  • Reversing an action (if supported by the action):
    • CCActionReverse

Creating Sequences of Actions

  • Creating a linear sequence of actions:
    • CCActionSequence
    • Wait for a given time in a CCActionSequence:
      • CCActionDelay
    • Spawning parallel running actions in a CCActionSequence and continue the sequence when all spawned actions have ended:
      • CCActionSpawn

Easing the Duration of an Action

  • Easing duration of a CCActionInterval:
    • CCActionEase
    • CCActionEaseBackIn, CCActionEaseBackInOut, CCActionEaseBackOut
    • CCActionEaseBounce, CCActionEaseBounceIn, CCActionEaseBounceInOut, CCActionEaseBounceOut
    • CCActionEaseElastic, CCActionEaseElasticIn, CCActionEaseElasticInOut, CCActionEaseElasticOut
    • CCActionEaseRate, CCActionEaseIn, CCActionEaseInOut, CCActionEaseOut
    • CCActionEaseSineIn, CCActionEaseSineInOut, CCActionEaseSineOut

Animating custom float/double Properties

  • Tweening any node property (of type float or double):
    • CCActionTween

Tasks

Other Methods

  •   elapsed property

Creating a Interval Action

  • + actionWithDuration:
  • – initWithDuration:

Reversing an Action

  • – reverse

Methods implemented by Subclasses

  • – isDone

Properties

elapsed

How many seconds had elapsed since the actions started to run.

自从动作被执行后过了多久。

@property (nonatomic, readonly) CCTime elapsed

Declared In

CCActionInterval.h

Class Methods

actionWithDuration:

Creates and returns an action interval object.

创建和返回一个action间隔对象。

+ (id)actionWithDuration:(CCTime)d

Parameters

d

Action interval.

Return Value

The CCActionInterval object.

Declared In

CCActionInterval.h

Instance Methods

initWithDuration:

Initializes and returns an action interval object.

- (id)initWithDuration:(CCTime)d

Parameters

d

Action interval.

Return Value

An initialized CCActionInterval Object.

Declared In

CCActionInterval.h

isDone

Returns YES if the action has finished.

- (BOOL)isDone

Return Value

Action finished status.

Declared In

CCActionInterval.h

reverse

Returns a reversed action.

- (CCActionInterval *)reverse

Return Value

Created reversed action.

Declared In

CCActionInterval.h
 
 

 

CCActionMoveTo Class Reference

Inherits fromCCActionMoveBy : CCActionInterval : CCActionFiniteTime : CCAction : NSObject
Declared inCCActionInterval.h

Overview

This action moves the target to the position specified, these are absolute coordinates. Several CCMoveTo actions can be concurrently called, and the resulting movement will be the sum of individual movements.

Warning: Move actions shouldn’t be used to move nodes with a dynamic CCPhysicsBody as both the physics body and the action will alter the node’s position property, overriding each other’s changes. This leads to unpredictable behavior.

Tasks

Creating a Move Action

  • + actionWithDuration:position:
  • – initWithDuration:position:

Class Methods

actionWithDuration:position:

Creates the action.

+ (id)actionWithDuration:(CCTime)duration position:(CGPoint)position

Parameters

duration

Action interval.

position

Absolute position to move to.

Return Value

New moveto action.

Declared In

CCActionInterval.h

Instance Methods

initWithDuration:position:

Initializes the action.

- (id)initWithDuration:(CCTime)duration position:(CGPoint)position

Parameters

duration

Action interval.

position

Absolute position to move to.

Return Value

New moveto action.

Declared In

CCActionInterval.h

CCAction Class 和 CCActionInterval Class 和 CCActionMoveTo Class ---Cocos2D-Swift v3.3