简体   繁体   中英

Box2D ChainShape VertexCount=0


Im working with Box2D on LibGDX, and I'm working with bodies and collisions etc..
HERE , i had the problem of a body colliding with another, when it shouldn't do that.
Now after Knowing that i need to use ChainShapes, i started with that.
Whenever u run my project, i get an assertion error:

Assertion failed: (count >= 2), function CreateChain, file /Users/tom/Coding/slave/workspace/libgdx-mac/extensions/gdx-box2d/gdx-box2d/jni/Box2D/Collision/Shapes/b2ChainShape.cpp, line 62.


So i tried a small debug to print the vertex count, and the vertex out printed as 0.
Problem is that i am adding the vertices and they dont appear to be added...
Code for adding verticies:

    chain = new ChainShape();
    chain.setNextVertex(new Vector2((posx - size) / PPM, (posy + size) / PPM));
    chain.setNextVertex(new Vector2((posx + size) / PPM, (posy + size) / PPM));
    chain.setNextVertex(new Vector2((posx + size) / PPM, (posy - size) / PPM));
    chain.setNextVertex(new Vector2((posx - size) / PPM, (posy - size) / PPM));
    System.out.println(chain.getVertexCount());


Vertex count is printed as 0, thats why i am getting the error, I dont know how to fix it, so please help :)

Create your ChainShape in this way :

ChainShape chain=new ChainShape();

Vector2 vector[]=new Vector2[4];
vector[0]=new Vector2((posx - size) / PPM, (posy + size) / PPM);
vector[1]=new Vector2((posx + size) / PPM, (posy + size) / PPM);
vector[2]=new Vector2((posx + size) / PPM, (posy - size) / PPM);
vector[3]=new Vector2((posx - size) / PPM, (posy - size) / PPM);

chain.createChain(vector);

System.out.println(chain.getVertexCount());  // 4 on console

If still you've problem, check the value of posx , posy , size , PPM

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM