Box2d Sprite不显示在多边形的中心

时间:2013-02-13 15:17:46

标签: ios box2d sprite

将精灵添加到自定义多边形时,我有一个奇怪的问题,它不会显示在多边形的中心,而是显示在左上角。 就像在那张照片上一样:http://pbs.twimg.com/media/BC8onkHCUAAwMVM.png:large

//4th polygon
    b2Vec2 vertices4[4];
    vertices4[0].Set(0, 0);
    vertices4[1].Set(1, -0.5);
    vertices4[2].Set(2, -0.5);
    vertices4[3].Set(3, 0);

    island = [CCSprite spriteWithFile:@"island.png"];
    island.position = ccp(18, 5);
    [self addChild:island];

    b2BodyDef myBodyDef4;
    myBodyDef4.type = b2_staticBody;
    myBodyDef4.userData = island;

    b2PolygonShape polygonShape4;
    polygonShape4.Set(vertices4, 4); //pass array to the shape

    b2FixtureDef myFixtureDef4;

    myFixtureDef4.shape = &polygonShape4; //change the shape of the fixture
    myBodyDef4.position.Set(18,5); 
    b2Body *staticBody4 = world->CreateBody(&myBodyDef4);
    staticBody4->CreateFixture(&myFixtureDef4); //add a fixture to the body

0 个答案:

没有答案