-
Minh KokoxLikes 0Problem Description
Hello,
I had an error with creating polygon physic body for a sprite:
{
auto mSprite = Sprite::create("");
std::array<Point, 6> mBodyPoint = {
Point(x1, y1),
Point(x2, y2),
Point(x3, y3),
Point(x4, y4),
Point(x5, y5),
Point(x6, y6)
}
auto mBody = PhysicsBody::createPolygon(mBodyPoint.data(), mBodyPoint.size(), PhysicsMaterial(1, 0.8, 1));
mBody->setDynamic(true);
mSprite->setPhysicsBody(mBody);
mSprite->setPosition(Vec2(xx1,yy2));
addChild(mSprite);}
It worked with ‘createEdgePolygon’.
Thanks for your help!
-
Sonar Systems adminLikes 0
What error did you receive.
-
Minh KokoxLikes 0
Here:
_________________________________________________________
Debug error!
Program: C:/.../.../...exe
R6010
– abort() has been called
__________________________________________________________
I used Visual Studio 2013 on win10pro. You should try this code on your computer to see the error!
-
Sonar Systems adminLikes 0
Does a fresh project work for you.
-
Minh KokoxLikes 0
I don’t understand! My project is failed now.
This code makes error with ‘createPolygon’ but works with ‘createEdgePolygon’. I need ‘createPolygon’ for my sprite.
-
Sonar Systems adminLikes 0
???
-
Minh KokoxLikes 0
You haven’t understood me yet!
Please try this code above, you will understand my problem!!!!
-
Sonar Systems adminLikes 0
I am unable to test it ATM, could you show me a screenshot of the error.
-
Minh KokoxLikes 0
Here:
After I run it:
https://drive.google.com/open?id=0B7sQdW0uEZZLUkI2VmFTbWxFaXM;
and lick ‘Retry’
https://drive.google.com/open?id=0B7sQdW0uEZZLUDFLVmp6X3dXTVE;
I lick ‘Break’ and it points to CCPhysicsShape.cpp:
https://drive.google.com/open?id=0B7sQdW0uEZZLZWE0T3VIOTh0c0E.
Is it enough for you?
What’s ATM?
-
Sonar Systems adminLikes 0
What’s the Physics helper?
-
Minh KokoxLikes 0
I don’t know!
-
Sonar Systems adminLikes 0
Where did you get the code from?
-
Minh KokoxLikes 0
In: [Cocos2dx file]\tests\cpp-tests\Classes\PhysicsTest\PhysicsTest.cpp
…….
void PhysicsDemoPump::onEnter()
{…..
Vec2 vec[4] =
{
VisibleRect::leftTop() + Vec2(102, -148),
VisibleRect::leftTop() + Vec2(148, -161),
VisibleRect::leftBottom() + Vec2(148, 20),
VisibleRect::leftBottom() + Vec2(102, 20)
};
// pump
auto pump = Node::create();
auto center = PhysicsShape::getPolyonCenter(vec, 4);
pump->setPosition(center);
auto pumpB = PhysicsBody::createPolygon(vec, 4, PHYSICSBODY_MATERIAL_DEFAULT, -center);
pump->setPhysicsBody(pumpB);
this->addChild(pump);…..
}
…….
I used ‘Point’ instead of ‘Vec2’ but they are the same.
-
Sonar Systems adminLikes 0
Have you seen our tutorials http://www.sonarlearning.co.uk/coursepage.php?topic=game&course=cocos2d-x-v3-cplusplus-physics
-
Minh KokoxLikes 0
I saw completely all of them. This tutorial has custom physic bodies video but ‘poligon body’ is better than ‘BodyParser physic body’.
I can change its size by changing data in:
std::array<Point, n> mBodyPoint { ….. } if it dose not make error.
So I want to use it.
-
Sonar Systems adminLikes 0
Did you follow a tutorial?
Login to reply