Custom physicsbody 凹 by cocos2dx

Custom physicsbody 凹 by cocos2dx
0.0 0


I have two questions.

1, I saw the sprite move around in the red frame. This is not a problem. But, sprites moving at high speed can pass through walls. Is this a bug?

2, I want to add a body to a dented shape. But I can not make a Physicsbody at once by PhysicsWorld rule.
So I divided it into three. This code is wrong, but what I want to do is here.
I would like to put the Physicsbody divided into three in one figure.
Please tell me the correct code. Thanks


auto sprite = Sprite::create(“aaaa.png”);
if (sprite == nullptr)
sprite->setPosition(Vec2((visibleSize.width/2 + origin.x) +0, (visibleSize.height/2 + origin.y) -400));

Point spritePoints1[4] =
    Point(-68, 43), Point(-55, 43), Point(-55, -8), Point(-68, -8)

Point spritePoints2[4] =
Point(68, 43), Point(55, 43), Point(55, -8), Point(68, -8)
Point spritePoints3[4] =
Point(-68, -8), Point(68, -8), Point(68, -43), Point(-68, -43)

auto sprBody = PhysicsBody::createPolygon(spritePoints1, spritePoints2, spritePoints3, 4, PhysicsMaterial(0.0f, 0.0f, 0.5f));
this->addChild(sprite, 1);


You need continuous collision detection.


Write with more info.

p.s. why forum not auto merge prev. posts?


You need to set bitmasks for collisions etc


Sorry what do you mean?


Auto Merge Posts Questions


Why is this even in this thread? It is not on topic and just pollutes the conversation.


Just example of what is merging last messages in topic.


Its not even related to the topic. The OP never mentioned merging anything.


That makes sense.


Sorry. I rewrote the explanation.


Anyway really hard to read and understand you… It’s very bad EN translator you’re using probably. Good luck.

  1. You need to set bitmasks It will trigger a collision event.

  2. I don’t understand this. Make 3 rectangles, give them Physics bodies, set bit masks. Put whatever you want in the middle, give it a physics body and a bitmask that is NOT the same as #1. Then the thing in the middle will bounce off the rectangles or whatever you wish to happen. It will trigger a collision event.


Sorry. I know what you mean.

I have a dented shape. So I want to solve this problem by coding without using software.


I solved the problem using "createEdgeChain"