About the classes used by the Cocos2d-x physics engine and the use

Source: Internet
Author: User

In fact, this is the three classes of Physicsworld class, Physicsbody class, Physicsshape class.

1.PhysicsWorld class

The Physicsworld object represents the physical world in Cocos2d-x, a world that can be used to simulate collisions and other physical properties. Instead of creating a Physicsworld object directly, it is recommended to get the Physicsworld object from a Scene object, Scene->getphysicsworld ().

2.PhysicsBody class

The Physicsbody object represents a rigid body in the physical world, and a rigid body can be attached to one or more shapes. If you create a rigid body object through the createxxx () function, the mass and torque are automatically calculated based on the density.

3.PhysicsShape class

The Physicsshape object represents the shape of a rigid body and some other properties that can be set to some density, mass, elasticity, and so on.

To set up a rigid body for an Elf object:

1. Create a Sprite object ball

2. Create a Body body

3. Adjust the properties of this rigidbody with the Physicsshape pointer object

Physicsshape *ps=body->getshape (0);

Ps->setmass (0.2f);


4. Set the body properties of this sprite object

Ball->setphysicsbody (body);

5. Add this Sprite object to the layer

This->addchild (ball);

The 13th chapter of the book on the Code of the physical world test that part, I feel very likely the author is to use gravity sensor on the phone to control the object or to achieve gravity, so wrote the device accelerometer method and accelerometer listener.

About the classes used by the Cocos2d-x physics engine and the use

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.