On the setting of the physical rigid body of polygons in cocos2d-x

Source: Internet
Author: User

1. If you want to set an object with a polygonal body, so that more accurate collision detection, you can use the following methods

Auto hero = Planehero::create ();
AddChild (Hero, 0, Hero_tag);
Hero->setposition (VEC2 (WINSIZE.WIDTH/2, Hero->getcontentsize (). HEIGHT/2 + 10));
Auto Herobody = Physicsbody::createbox (Hero->getcontentsize ()); This setting is not very precise.
Auto Herobody = Physicsbody::create ();
VEC2 verts[] = {VEC2 (0), VEC2 ( -30), VEC2 (-50,-30)}; A polygon is formed from a point so that the physicsbody set is a triangle
Herobody->addshape (Physicsshapeedgepolygon::create (Verts, 3));
Herobody->setcollisionbitmask (0x0); No collision simulation
Herobody->setcontacttestbitmask (Hero_contactmaskbit);
Hero->setphysicsbody (Herobody);

2. About the Physicsshapeedgepolygon function

Static physicsshapeedgepolygon* Create (const VEC2 * points, int count, const physicsmaterial & material = Physicss Hape_material_default, float border = 1)

An array of points polygon vertices.
Count Polygon Vertex count.
MATERIAL physical Material Physicsmaterial object, default value is Physicsshape_material_default.
Border This is the border width of the polygon.

Example

VEC2 verts[] = {VEC2 (0), VEC2 ( -30), VEC2 (-50,-30)}; Make a polygon based on points

Herobody->addshape (Physicsshapeedgepolygon::create (Verts, 3));

On the setting of the physical rigid body of polygons in cocos2d-x

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.