[IOS-Cocos2d game development thirteen] ccsprite using beiser (bésel) parabolic action and let ccsprite play two action at the same time!

Source: Internet
Author: User

Li huaming himiOriginal, reprinted must be explicitly noted:
Reprinted from[Heimi gamedev block]Link: http://www.himigame.com/iphone-cocos2d/480.html

If we want to make ccsprite perform parabolic motion, we think that children's shoes will first think of using box2d or other physical engines to create the corresponding rigid bodies in the physical world for ccsprite, however, it is inconvenient for children's shoes that are not familiar with box2d or other physical engines. Therefore, himi will introduce another non-practical physical engine implementation ccsprite parabolic method;

Here I directly paste the encapsulated method, and the comments are in the Code:

// Parabolic-himi // msprite: The Wizard that requires parabolic results // startpoint: Start position // endpoint: Stop position // dirtime: time required from the start position to the stop position-(void) movewithparabola :( ccsprite *) msprite startp :( cgpoint) startpoint endp :( cgpoint) Endpoint dirtime :( float) time {float SX = startpoint. x; float Sy = startpoint. y; float EX = endpoint. X + 50; float ey = endpoint. Y + 150; int H = [msprite contentsize]. height * 0.5; ccbezierconfig betiller; // create the betiller curve. controlpoint_1 = CCP (sx, Sy); // the starting point of this parameter. controlpoint_2 = CCP (SX + (ex-SX) * 0.5, SY + (ey-sy) * 0.5 + 200); // Control Point bezr. endposition = CCP (endpoint. x-30, endpoint. Y + H); // The end position ccbezierto * actionmove = [ccbezierto actionwithduration: Time besuppliers: besuppliers]; [msprite runaction: actionmove];}

Previously, I have explained the bersel curve blog on Android. However, unlike cocos2d encapsulation, bejies in cocos2d are encapsulated as Genie actions, let the genie follow the route of the besell curve. The most important point in the Code encapsulated above for the parabolic motion is to create the second point of the besell curve, this point controls the highest point of the sprite path, so you must know it here;

Although this implementation method does not have the physical system to exert force on the rigid body! I think this code is very practical. At least you do not need to use the box2d engine. The most important advantage is that there will be no compilation errors caused by the mixed Code introduced in the previous chapter ~

// ---- OK. The second knowledge point is introduced below:

Many children's shoes learn cocos2d. Generally, less frequently updated animations use cocos2d encapsulated actions, such as rotation, gradient, and displacement. Once an action is used, there must be a need to play two actions together. Basically, the first flash in the shoes is to use the cocos2d action sequence ccsequence, but the effect is not ideal. The reason is very simple, because, as the name suggests, since it is an action sequence, it means playing an action in the order of actions. That is to say, the action sequence can only be used to play continuously and cannot play simultaneously;

Here we will provide you with a method to enable simultaneous playback of two actions:

For ease of explanation, I modified the method on the beiser curve just encapsulated and added a rotating action to play the beiser curve movement and rotating action at the same time, here, himi uses a "Spear" image to illustrate the effect, because the most common movement of the spear and arrow is to rotate one side of the parabolic displacement, so that it is more real;

OK. Check the parabolic curve after the encapsulation angle and rotate it at the same time as follows:

// Parabolic motion and rotating at the same time-himi // msprite: The Wizard that requires parabolic performance // startpoint: Start position // endpoint: Stop position // starta: Start angle // ENDA: abort angle // dirtime: The time required from the starting position to the abort position-(void) movewithparabola :( ccsprite *) msprite startp :( cgpoint) startpoint endp :( cgpoint) Endpoint starta :( float) startangle ENDA :( float) endangle dirtime :( float) time {float SX = startpoint. x; float Sy = startpoint. y; float EX = endpoint. X + 50; float ey = endpoint. Y + 150; int H = [msprite contentsize]. height * 0.5; // set the sprite's starting angle. rotation = startangle; ccbezierconfig besuppliers; // create the besuppliers curve. controlpoint_1 = CCP (sx, Sy); // the starting point of this parameter. controlpoint_2 = CCP (SX + (ex-SX) * 0.5, SY + (ey-sy) * 0.5 + 200); // Control Point bezr. endposition = CCP (endpoint. x-30, endpoint. Y + H); // The end position ccbezierto * actionmove = [ccbezierto actionwithduration: Time besuppliers: besuppliers]; // The ccrotateto * actionrotate = [ccrotateto actionwithduration: Time angle: endangle]; // encapsulate two actions into one action for simultaneous playback. ccaction * Action = [ccspawn actions: actionmove, actionrotate, nil]; [msprite runaction: Action];}

Attached run:

The spear on the left is the starting position, while the parabolic side and the rotation side are the spears in motion at the same time ~

 

Well, let's talk about it so much. Today, the demo is coming out ~ Haha;

Related Article

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.