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