Cocos2D-X TestCPP (a) Action on
The previous blog posts did not systematically introduce a series of knowledge. Today, I learned a lot from my advice. Since now many students have just come into contact with Cocos2D-X, but also seeking some good teaching materials. So the best teaching material of Cocos2D-X is built-in TestCPP does not belong. I will also insist on writing a series of blog posts such as TestCPP. This allows new users to use as teaching materials. Experts can use it as a Chinese API.
Okay, let's talk less. After TestCPP is run, the first Action is commonly used in the game. Because there are too many actions, let's introduce them first.
PS: Since 2.0.4 has been used for a long time, it is said that it is too old, so the latest 2.1.3 is used.
First, open the ActionsCPP filter in the TestCPP project. The cpp of AcionsTest is in the eyes of everyone.650) this. width = 650; "src =" ../attachment/201305/203254199 .png" border = "0" alt = ""/>When we open ActionsTest. cpp, we will find a lot of code. However, today we will mainly introduce Action. The rest will not be introduced first. We found that there is a string of text on the first Action UI of ActionsTest in TestCPP. It is the mark of the red box in the figure. We need to use the content displayed at this position.650) this. width = 650; "src =" ../attachment/201305/203726104 .png" align = "middle" border = "0" alt = ""/>
Well, we know what to pay attention. In VS2010, we will search for text keys marked by red boxes.650) this. width = 650; "src =" ../attachment/201305/203944417 .png" border = "0" alt = ""/>We found the code above, which is the class of the currently displayed Action. TestCPP writes all the operations used in ActionsTest in a CPP, which is also convenient for us to view.The code used will be in his OnEnter method. We will try to find out as few as possible in the future.Manual Transformation:M_tamara-> setScaleX (2.5f );
M_tamara-> setScaleY (-1.0f );
M_tamara-> setPosition (ccp (100,70 ));
M_tamara-> setOpacity (180); // sets the transparency to 0-255.
M_grossini-> setRotation (120); // rotate the value above 0 to the right.
M_grossini-> setPosition (ccp (s. width/2, s. height/2 ));
M_grossini-> setColor (ccc3 (, 0, 0); // you can specify the sprite color.
M_kathia-> setPosition (ccp (s. width-100, s. height/2 ));
M_kathia-> setColor (ccBLUE); // set the color to blue.We can see that there are three objects: m_tamara, m_grossini, and m_kathia. These three genie represent the three villains respectively.
M_tamara is the girl with glasses. We call her Tamara.M_grossini is the bald hacker. We call it Grossini.M_kathia is the black girl. We call it Kathia.
Here, we only perform some color changing and location setting operations on the three of them, but they have nothing to do with the Action, so I will not mention it here.
MoveTo/MoveBy: Move
CCActionInterval * actionTo = CCMoveTo: create (2, ccp (s. width-40, s. height-40 ));
CCActionInterval * actionBy = CCMoveBy: create (2, ccp (80, 80 ));
CCActionInterval * actionByBack = actionBy-> reverse ();
M_tamara-> runAction (actionTo );
M_grossini-> runAction (CCSequence: create (actionBy, actionByBack, NULL ));
M_kathia-> runAction (CCMoveTo: create (1, ccp (40, 40 )));CCMoveTo: create parameter 1: execution time parameter 2: Target PointCCMoveBy: create parameter 1: execution time parameter 2: Mobile coordinate pointWe can see that there are two actions, CCMoveTo and CCMoveBy, which are literally difficult to separate, and many of the subsequent actions are also named. CCMoveTo is used to move to the specified coordinate point. And CCMoveBy is based on the current coordinate point and moved above it. CCMoveTo eventually replaces the coordinates, while CCMoveBy adds the coordinates you provided to the original coordinates.After creating an action, the runAction must be executed by the Genie. Otherwise, the action will not be executed.CCSequence: This is an action sequence. When you want the genie to execute a series of actions, the genie will perform the actions you provide in the order of parameters, of course, you must use NULL as the end of the parameter.
RotateTo/RotateBy: Rotate
CCActionInterval * actionTo = CCRotateTo: create (2, 45 );
CCActionInterval * actionTo2 = CCRotateTo: create (2,-45 );
CCActionInterval * actionTo0 = CCRotateTo: create (2, 0 );
M_tamara-> runAction (CCSequence: create (actionTo, actionTo0, NULL ));
CCActionInterval * actionBy = CCRotateBy: create (2,360 );
CCActionInterval * actionByBack = actionBy-> reverse ();
CCRotateTo: create parameter 1: execution time parameter 2: Rotation AngleCCRotateBy: create parameter 1: execution time parameter 2: Rotation Angle
Here, a new function is actionBy-> reverse. This function is used to reverse your actionBy action. For example, if actionBy is rotated 60 degrees, then actionBy-> reverse is a rotation-60 degrees action, which will let the genie Return to the status before performing this action.
ScaleTo/ScaleBy: Scaling and Expansion
CCActionInterval * actionTo = CCScaleTo: create (2.0f, 0.5f );
CCActionInterval * actionBy = CCScaleBy: create (2.0f, 1.0f, 10.0f );
CCScaleTo: create parameter 1: execution time parameter 2: scaling ratioCCScaleTo: create parameter 1: execution time parameter 2: X axis Scaling Parameter 3: Y axis ScalingCCScaleBy: create parameter 1: execution time parameter 2: Zoom Ratio
SkewTo/SkewBy: I don't know how to describe it .)
CCActionInterval * actionTo = CCSkewTo: create (2, 37.2f,-37.2f );
CCActionInterval * actionToBack = CCSkewTo: create (2, 0, 0 );
CCSkewTo: create parameter 1: execution time parameter 2: X axis degree parameter 3: Y axis degreeCCSkewBy: create parameter 1: execution time parameter 2: X axis degree parameter 3: Y axis degree
RotationalSkewTo/RotationalSkewBy: rotation skew
CCRotateTo * actionTo = CCRotateTo: create (2, 37.2f,-37.2f );
CCRotateBy * actionBy = CCRotateBy: create (2, 0.0f,-90.0f );
Skew Comparison: Skewed Layer)
CCSkewBy * actionTo = CCSkewBy: create (2,360, 0 );
CCSkewBy * actionToBack = CCSkewBy: create (2,-360, 0 );
Skew + Rotate + Scale: multiple actions at the same time
Box-> runAction (CCSequence: create (actionTo, actionToBack, NULL ));
Box-> runAction (CCSequence: create (rotateTo, rotateToBack, NULL ));
Box-> runAction (CCSequence: create (actionScaleTo, actionScaleToBack, NULL ));We found that we used to execute an action/action sequence. Here we have executed three action sequences at the same time. This is feasible. If you don't believe it, try to comment out the code ~ These three action sequences are synchronized.
JumpTo/JumpBy: Skip
CCActionInterval * actionTo = CCJumpTo: create (2, ccp (300,300), 50, 4 );
CCActionInterval * actionBy = CCJumpBy: create (2, ccp (, 0), 50, 4 );
M_kathia-> runAction (CCRepeatForever: create (actionUp ));
CCJumpTo: createParameter 1: Time Parameter 2: Target point parameter 3: Maximum hop height parameter 4: Number of hopsCCJumpBy: createParameter 1: Time Parameter 2: Moving Point parameter 3: Maximum hop height parameter 4: Number of hopsHere we find that CCRepeatForever: create will make the action as a parameter infinitely, starting from the first one after each execution, like some happy NPCs can use this to do it.
Well, today we will introduce that there are not many actions. Next time, I will introduce the part that will be moved from the besell curve. Next time, see.CocoStudio discussion and learning group:141444261Cocos2D-X discussion Learning Group:244959010Update!Cocos2D-X TestCPP (a) Action onHttp://502317120.blog.51cto.com/4062300/1194396
This article from the "Zhang Pengfei" blog, please be sure to keep this source http://502317120.blog.51cto.com/4062300/1193712