我正在使用 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.sprite
PhysicsSprite
nodeToParentTransform
PTM_RATIO = 32