Cocos2dx3.2 Study Notes (2) -- ActionManagerTest, cocos2dx3.2

Source: Internet
Author: User

Cocos2dx3.2 Study Notes (2) -- ActionManagerTest, cocos2dx3.2

I have read the basic framework and process of CppTests. Now I want to see the specific Test.

Where can I start. (ActionManagerTest)

 

First, let's take a look at the results. After running, we found several effects. I can't see any name, but it's a bit strange.

Open the code and first look at the header file. It turns out that it is not a class, but several classes are put here. The Estimation of ActionManagerTest is just a few results, and there are few methods. It is not hard to find out, basically, the first two methods are both

Sample. Only the third method is different. Go to the cpp file and check the situation. First, define an enumeration. I don't know what to do. Then I declare three functions to check what the name is.

Directly paste the code and annotate it.

Layer * nextActionManagerAction (); -- next action
Layer * backActionManagerAction (); -- previous action
Layer * restartActionManagerAction (); -- reset action

Static int sceneIdx =-1; then an index is defined.

# Define MAX_LAYER 5 defines the maximum number of layers

Create a layer based on the index

Layer * createActionManagerLayer (int nIndex)
{

// When I was learning, I directly returned a specific layer here, one by one to see what the results returned new CrashTest ();
Switch (nIndex)
{
Case 0: return new CrashTest ();
Case 1: return new LogicTest ();
Case 2: return new PauseTest ();
Case 3: return new StopActionTest ();
Case 4: return new ResumeTest ();
}

Return nullptr;
}

The next action button calls back and changes the index.

Layer * nextActionManagerAction ()
{
SceneIdx ++;
SceneIdx = sceneIdx % MAX_LAYER;

Auto layer = createActionManagerLayer (sceneIdx );
Layer-> autorelease ();

Return layer;
}

Callback of the previous action button to change the index

Layer * backActionManagerAction ()
{
SceneIdx --;
Int total = MAX_LAYER;
If (sceneIdx <0)
SceneIdx + = total;

Auto layer = createActionManagerLayer (sceneIdx );
Layer-> autorelease ();

Return layer;
}

Reset current action

Layer * restartActionManagerAction ()
{
Auto layer = createActionManagerLayer (sceneIdx );
Layer-> autorelease ();

Return layer;
}

 

Similarly, I first saw the first CrashTest ();

Auto child = Sprite: create (s_pathGrossini); // create an genie
Child-> setPosition (VisibleRect: center (); // you can specify the position in the center.
AddChild (child, 1); // Add to current layer

// Sum of all action's duration is 1.5 second.
Child-> runAction (RotateBy: create (1.5f, 90); // The RotateBy function indicates that it is a rotation (90 degrees in 1.5 seconds)
Child-> runAction (Sequence: create (// The Sequence function is not clear at all. It means the action Sequence, which should be an action.
DelayTime: create (1.4f), // a wait action is triggered for 1.4 seconds.
FadeOut: create (1.1f), // fade in for 1.1 seconds
Nullptr)
);

// After 1.5 second, self will be removed.
RunAction (Sequence: create (
DelayTime: create (1.4f), // a wait action is triggered for 1.4 seconds.
CallFunc: create (CC_CALLBACK_0 (CrashTest: removeThis, this), // execute a callback
Nullptr)

I thought the code was a genie. After 90 degrees of rotation, wait for 1.4 seconds and then fade in. Then wait for 1.4 seconds and then execute the callback.

This is not the case. I commented out the code and executed the actions one by one. Later, I found that the three runactions were executed together.

That is, the first 1.5 seconds of rotation at the same time 1.4 seconds of waiting, to 1.5 seconds, you should buy not rotate to 90 degrees, and then the execution should fade in, we also found that the callback is to be executed, and the result is directly executed to the callback.

It indicates that the action is executed at the same time and interrupts the previous action. I think the sample code can change the wait time of the third runAction to 2.5 seconds, so that we can see a complete process. The second runAction shows that the action will not be interrupted. I did not understand the original intention of the author.

The remaining callback is removeThis.

Void CrashTest: removeThis ()
{
_ Parent-> removeChild (this, true); -- delete yourself

NextCallback (this); -- creates the next layer
}

 


In order to reward students in Class 3 of Grade 7 for learning and progress, they purchased a notebook with a unit price of 3 yuan and a pen with a unit price of 5 yuan for 2 yuan prize, which cost a total of 35 yuan.

Set notebook to x, pen to y
3x + 5y = 35
Buy all pens, x = 0, y = 7
Y = 4, x = 3
Y = 1, x = 10

 
James went to the store to buy school supplies. It is known that he needs 32 yuan to buy 20 pencils, 3 erasers, and 2 laptops. He needs 5 yuan to buy 39 pencils, 5 fast erasers, and 3 laptops.

1 yuan for every pencil, 2 yuan for every rubber, 3 yuan for the notebook, so the final answer is 30 yuan.

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.