Cocos2dx3. X Project rewriting (2) New physical Engine

Source: Internet
Author: User

The new physical engine is physicsbody.

Create physical scene

 
Auto scene = scene: createwithphysics ();
 
Add debugging information so that the box attached to the rigid body is displayed.
 
Scene-> getphysicsworld ()-> setdebugdrawmask (physicsworld: debugdraw_all );

 
 
Create border box

 
Void stage: addedgebox () {auto visiblesize = Director: getinstance ()-> getvisiblesize (); // create a rigid body auto edgebox = physicsbody: createedgebox (visiblesize ); // Create Image Auto shape = node: Create (); // attach a rigid body to the image shape-> setphysicsbody (edgebox); this-> addchild (SHAPE );}
 
The default position of the shape is (0, 0), but this is the center of the node. We set it to the center of the screen.

 
Shape-> setposition (visiblesize. width/2, visiblesize. Heigh

After setting the world, you only need one sentence to change the sprite player to a rigid body.

 
Player-> setphysicsbody (physicsbody: createbox (player-> getcontentsize ()));
At this time, if you place the position of the genie in the middle of the screen, you can see the fall of the genie, because of the gravity, and there will be a rebound to the ground.




 
 
 
 

Cocos2dx3. X Project rewriting (2) New physical Engine

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.