Action ccaction for Cocos2d-iphone Development

Source: Internet
Author: User

(1)

From the code point of view, action is actually to change the attributes of an object node, such as coordinates, angles, and sizes. Most of these attributes can be set by the encapsulated methods of the Action object class, these actions are encapsulated into specific classes, which makes coding easier if you want a node to execute a behavior sequence or repeatedly execute a behavior, you can create an instance object for the class.

The base class of the behavior class is ccaction, and any kind of behavior is derived from its extension. The behavior categories can be divided into four categories: limited execution, unlimited repetitive behavior, speed behavior, and follow-up mobility. The first two are most frequently used; the limited execution class can be divided into instantaneous behavior class and process behavior class. Their Inheritance relationships include:


The ccaction in the figure is a base class, which is abstract and not directly used in actual development. It is more like 'generics 'in parameter passing ';

Ccfinitetimeaction can be seen literally (finite = Limited). It is a finite execution class. It is the most common behavior, that is, to do a series of things in chronological order, and the behavior ends after completion; it can be divided into two types of actions: interval action and instantaneous action,If these Action attributes are modified after a period of time, these actions are interval actions: ccactioninterval; otherwise, they are instantaneous actions: ccactioninstance. For example, moving, jump, and scale actions are interval actions, while place, show, and hide actions are instantaneous actions.

The ccrepeatforever name is more understandable, and the behavior class is infinitely repeated. That is to say, it allows the node to do one thing repeatedly, and will never stop unless the behavior or node is deleted;

The function of ccspeed is to adjust the execution speed of the behavior instance. Therefore, it depends on other behaviors. it is meaningless to separate ccspeed;

Ccfollow allows a node to move following another specified node.


Ccactionmanager

This class is not actually a behavior class. Its parent class is nsobject rather than ccaction, but it is inseparable from ccaction.

Ccactionmanager is a standard Singleton class. Its role, as its name implies, is to manage the behavior class objects. its working principle is: when a node executes runaction, the action is passed to the singleton of ccactionmanager through the addaction method, and the instance then adds the action to its own behavior sequence. Ccactionmanager uses Schedule to regularly refresh its update method. In this method, call the step of each action in the behavior sequence (there are some filtering conditions, for example, paused behavior will not be updated ), these step methods then update or end the behavior based on their completion progress. That is to say, each action driven by ccactionmanager updates its own logic, while the runaction method only adds the behavior object to the update queue of ccactionmanager. When the node is cleared or the action ends, ccactionmanager automatically removes the action from the queue, so developers do not have to worry about it.

(2)

Action name suffix by action is called relative action, and action name suffix to action is called absolute action, The former, and the latter have their own reverse reversal actions.

Explain the differences between by and:

To: Indicates absolute.

By: Indicates relative.

Example:

CCSprite *sprite = [CCSprite spriteWithFile:@"my.png"];    CCMoveBy *moveBy = [CCMoveBy actionWithDuration:2.0f position:ccp(100, 50)];    [sprite runAction:moveBy];

Explanation: The position parameter is related to by and. Note position: CCP (, 50)
① If it is by, it indicates relative, which means that, relative to my current node, 100 units are moved to the right, and 50 units are moved up. ② If it is to, it indicates absolute, so it means that the node is moved to the Coordinate Position (, 50), then the Relative zero position of the screen is calculated here. (The node here is sprite)


(3) Classification and use of actions

1. Location-related actions

(1) ccmoveto/ccmoveby: Motion

(2) ccjumpto/ccjumpby: jumps along the parabolic curve.

(3) ccbezierto/ccbezierby)

(4) ccplace: place the Node object directly at the desired position

2. action related to the size

(1) ccscaleto/ccscaleby: Zoom In or out to a specific proportion

3. Rotation-related actions

(1) ccrotateto/ccrotateby: rotating

4. Actions related to display

(1) ccshow: displays node objects immediately

(2) cchide: Hide node objects now

(3) cctogglevisibility: switches the visual attributes of node objects.

(4) ccblink: a specific number of flashes within a certain period of time

5. transparency-related actions

(1) ccfadein: fade in

(2) ccfadeout: fade out

(3) ccfadeto: modifies the transparency of a Node object to a specific value.

6. Color-related actions

(1) cctintto/cctintby: colors nodes to a specific RGB color value.

7. Actions related to flip

(1) ccflipx: horizontal direction

(2) ccflipy: vertical

8. Combined Action

(1) ccspawn: enables the node to execute multiple actions at the same time (the time interval of the combined action is the one with the longest time interval of the Action)

(2) ccsequence: enables the node to execute multiple actions in sequence

(3) ccrepeat: enables the node to repeat an action.

(4) ccrepeatforever: enables the node to execute an Action repeatedly

9. Merge Action: A special combination action that can modify the speed of an internal action.

10. delayed action

(1) ccdelaytime

11. Method callback action: (the last three parameters are included)

Parameter: (N: node D: Data O: Object)

(1) cccallfunc

(2) cccallfuncn

(3) cccallfuncnd

(4) cccallfunco

12. Block statement call Action: (the last two parameters are available)

(1) cccallblock

(2) cccallblockn

(3) cccallblocko

13. Reversal

Note: The action with the suffix "to" usually does not support the reverse action. The action with the suffix "by" usually supports the reverse action.

(1) ccreversetimer

(2) [Action reverse] the reverse action can also be created, but only the ccactioninterval action can use the reverse method.

14. Special actions

(1) ccspeed

(2) ccactiontween

Note: To create these Action instances, you generally use the class method: actionwith --

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.