1

我正在使用 PhysicsSprite 类

我已经更改了这段代码:

transform_ = CGAffineTransformMake( c,  s,
                                   -s,  c,
                                   x,   y );

nodeToParentTransform方法上:

transform_ = CGAffineTransformMake( c * scaleX_,  s * scaleX_,
                                   -s * scaleY_,  c * scaleY_,
                                   x,   y );

问题是物理体放错了位置,正如您在此屏幕截图中看到的那样(在调试图中启用了 e_shapeBit):

方形僵尸

实体创建如下:

    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position.Set(brick.sprite.position.x/PTM_RATIO, brick.sprite.position.y/PTM_RATIO);
    bodyDef.userData = brick.sprite;
    b2Body *body = world->CreateBody(&bodyDef);
    body->SetGravityScale(0);
    brick.sprite.userData = body;

    b2PolygonShape dynamicBox;
    dynamicBox.SetAsBox(levelObj.brickScale * .5f, levelObj.brickScale * .5f);

    b2FixtureDef fixtureDef;
    fixtureDef.shape = &dynamicBox;
    fixtureDef.density = 1.0f;
    fixtureDef.friction = 0.3f;
    body->CreateFixture(&fixtureDef);

    body->SetType(b2_dynamicBody);
    brick.sprite.userObject = brick;
    [brick.sprite setPhysicsBody:body];

编辑: 对不起,我说得不够清楚:通过缩放我的意思是自然的 Cocos2D 构造,类的实例brick.sprite.scale = 0.5f在哪里。不修改它根本没有效果。砖块精灵是 32x32px,它提供 1x1m 的物理尺寸,因此是 SetBox 参数。brick.spritePhysicsSpritenodeToParentTransformPTM_RATIO = 32

4

2 回答 2

0

您不必修改nodeToParentTransform方法来支持缩放。你可以初始化你的身体的形状来匹配你的精灵的尺寸:

dynamicBox.SetAsBox(brick.sprite.contentSize.width/PTM_RATIO * brick.sprite.scaleX * .5f, brick.sprite.contentSize.height/PTM_RATIO * brick.sprite.scaleY * .5f);
于 2012-10-22T14:57:38.777 回答
0

最好的方法是在精灵高度和重量的帮助下创建身体。

于 2013-11-18T10:27:05.043 回答