I felt very angry when something happened this morning! At this time last year, my friends and I took graduation photos on the playground. Then a reporter from a local newspaper came to our school to learn materials, after seeing this, I plan to give us a few graduation photos with creative ideas. After that, the photo was taken out, and everyone was very satisfied with the effect. Finally, the photo was used as a layout for the Meizhou daily and school newspaper. This is one of the most proud tasks of my university. However, today, I found that this photo was taken as an illustration of a magazine by a city's male hospital. The title of this article is still "treating man xxx" (I am not sure to laugh, I am very serious ). Nima's, I saw the last two things, and I called the hospital to make a call. Fortunately, their wrong attitude was still sincere, so I did not go too far to investigate. This is the end of the incident. Who knows that a local forum has sent this event to the hype? I am new to Nima! Call me again! If I am a hacker, I don't want to hack your forum!
---------------
Drink water and breathe.
This introduction is really a pure skill, and there is no knowledge. Let's start with a few self-answer questions, also known as: throwing bricks and jade.
1. If you want an genie to first move to a coordinate and then rotate it, how can this problem be implemented?
A: Of course Sequence is used. The effect is too good!
2. If you want to play the animation of an object, play the animation of another object.
A: There are many implementation methods. You can use TargetedAction or Callfunc;
3. What should I do if I want to play multiple objects in different time periods of Android? A: use multiple Callfunc or TargetedAction. If you answer this question, I can only say that I have never used ActionManage, which is inconvenient to say. The following describes another feasible solution. That is, the combination of Array and Dictionary. First, put the executed action tag and the execution OBJECT tag of the action into the Dictionary, then put the Dictionary into the Array, and finally play the animation cyclically with a for statement in the Array.
Example:
Continue with our leading role: boy, girl, girl_3.
The procedure is as follows:
When the boy moved to the girl's side, he played a girl. The girl was so angry and angry that she beat the girl again. Then, the boy went to girl_3 again ),
The same formula is used on girl_3. girl_3 does not care about it, but is very happy to turn around.
1. First define a function to create the three required actions, and obtain the corresponding actions through the input integer parameters.
Sequence * HelloWorld: getAction (int action_tag) {if (1 = action_tag) // move {return Sequence: create (MoveTo: create (1.0f, point (300,200), CallFunc: create (CC_CALLBACK_0 (runMyAction, this), // call runMyAction to play the next animation NULL);} else if (2 = action_tag) // skip {return Sequence: create (JumpBy: create (1.0f, Point (350,200), 20, 2), CallFunc: create (CC_CALLBACK_0 (runMyAction, this )), NULL);} else if (3 = action_tag) // rotate {return Sequence: create (RotateBy: create (1.0f, 360), CallFunc :: create (CC_CALLBACK_0 (runMyAction, this), NULL);} else {CCLOG ("the action_tag is out of range"); return NULL ;}}
2. Create an object and initialize array and Dictionary
Bool HelloWorld: init () {auto boy = Sprite: create ("boy.png"); boy-> setPosition (Point (100,100); this-> addChild (boy, 1); auto girl = Sprite: create ("girl_1.png"); girl-> setPosition (Point (100,100); this-> addChild (girl, 1 ); auto girl_3 = Sprite: create ("girl_3.png"); girl_3-> setPosition (Point (100,100); this-> addChild (girl_3, 1 ); // initialize Array and Dictionary, and then put the object and action into auto action_array = Array: create (); action_array-> retain (); auto dic1 = Dictionary :: create (); auto dic2 = Dictionary: create (); auto dic3 = Dictionary: create (); dic1-> setObject (boy, "sp "); dic1-> setObject (Integer: create (1), "action"); // The action tag of the row is 1, action_array-> addObject (dic1 ); dic2-> setObject (girl, "sp"); dic2-> setObject (Integer: create (2), "action"); action_array-> addObject (dic2 ); dic3-> setObject (girl_3, "sp"); dic3-> setObject (Integer: create (1), "action"); action_array-> addObject (dic3 ); action_idx = 0; // Initialization is 0. When playing an animation, use // play the animation this-> runMyAction (); // runMyAction is a custom function, used to play the animation in the array return true ;}
3. Functions for playing an animation
Void HelloWorld: runMyAction () {action_idx ++; // action subscript + 1if (action_idx> action_array-> count () return; // The Last animation has been played, auto dic = static_cast
(Action_array-> getObjectAtIndex (action_idx); // retrieves the corresponding dictionary from the array through action_idx auto sp = static_cast
(Dic-> objectForKey ("sp"); // retrieves the object auto act_tag = static_cast
(Dic-> objectForKey ("action"); // retrieves the animation tagauto act = getAction (act_tag-> getValue () to be played ()); // extract the corresponding action from the getAction function using the action tag. sp-> runAction (act );}
Well, that's it. I haven't actually run it. Here I just want to show my friends a feasible way to play an animation. If you have other methods, you can share them.
This article is messy and may be related to today's impatience. I have long wanted to write this blog post, but I have never been able to spare time, so I have to write more about it tonight. It is indeed busy recently. Call
Respect Original, reprinted please indicate Source: http://blog.csdn.net/star530/article/details/25007815