如何在box2d中修复y角度为零的体

时间:2013-02-11 13:22:59

标签: cocos2d-iphone box2d

我正在做一场比赛。在那个移动的男孩精灵与身体创建。男孩的身体在前侧或后侧移动时会掉下来。

如何固定身体y轴0?

    CCSprite *boySprite=[CCSprite spriteWithFile:@"object_boy.png"];
    boySprite.position=ccp(100,50);

    b2BodyDef boyBodyDef;
    boyBodyDef.type = b2_dynamicBody;
    boyBodyDef.linearDamping = 1;
    boyBodyDef.angularDamping = 1;
    boyBodyDef.position.Set(25.0f/PTM_RATIO,(150)/PTM_RATIO);
    boyBodyDef.angle=0;
    boyBodyDef.userData = _boy;
    boyBody = world->CreateBody(&boyBodyDef);

    b2PolygonShape boyBox;
    b2FixtureDef boyBoxDef;
    boyBoxDef.shape = &boyBox;
    boyBoxDef.density = 0.5F;
    boyBox.SetAsBox(11.0f/PTM_RATIO, 30.0f/PTM_RATIO);
    boyFixture = boyBody->CreateFixture(&boyBoxDef);


    [self addChild:boySprite z:1];

1 个答案:

答案 0 :(得分:1)

将b2BodyDef中的fixedRotation设置为true。

 boyBodyDef.fixedRotation = true;