Quantcast
Channel: cocos2d-x - Cocos Forums
Viewing all articles
Browse latest Browse all 2748

Box2d positioning problem

$
0
0

@nichlaspro132 wrote:

Hi!

I have this code:

b2Body* bodies[3];
 //body definition
    b2BodyDef myBodyDef;
    myBodyDef.type = b2_dynamicBody;
    //shape definition
    b2PolygonShape polygonShape;
    polygonShape.SetAsBox(1, 1); //a 2x2 rectangle
    //fixture definition
    b2FixtureDef myFixtureDef;
    myFixtureDef.shape = &polygonShape;
    myFixtureDef.density = 1;
    //create identical bodies in different positions
    for (int i = 0; i < 3; i++) {
      myBodyDef.position.Set(-10+i*10, 20);
      bodies[i] = m_world->CreateBody(&myBodyDef);
      bodies[i]->CreateFixture(&myFixtureDef);
    }
    //a static floor to drop things on
    myBodyDef.type = b2_staticBody;
    myBodyDef.position.Set(0, 0);
    polygonShape.SetAsEdge( b2Vec2(-15,0), b2Vec2(15,0) );
    m_world->CreateBody(&myBodyDef)->CreateFixture(&myFixtureDef);

But the three generated boxes seem to have been placed way too much to the left?
Like the first one has a x position of lower than 0(I think)
Somebody knows why my box2d objects wont be placed where I suppose they should be?

Thanks

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 2748

Trending Articles