我有一个 CCSprite(其中我有一个 b2body);范围是创建一个随身体移动到一个位置并返回的精灵;
我以这种方式创建 b2body:
if (_body)
{
_world->DestroyBody(_body);
}
b2BodyDef bd;
bd.type = b2_kinematicBody;
_body = _world->CreateBody(&bd);
b2PolygonShape shape;
b2Vec2 _p1, _p2 , _p1sub,_p2sub;
_p1 = b2Vec2(point1.x/PTM_RATIO,point1.y/PTM_RATIO);
_p2 = b2Vec2(point2.x/PTM_RATIO,point2.y/PTM_RATIO);
shape.SetAsEdge(_p1, _p2);
_body->CreateFixture(&shape, 0);
创建主体后,我初始化动作:
id a1 = [CCMoveBy actionWithDuration:1 position:ccp(0,-self.position.y+destinationPoint.y)];
id action2 = [CCRepeatForever actionWithAction:
[CCSequence actions: [[a1 copy] autorelease], [a1 reverse], nil]
];
[self runAction:action2];
在每一帧上,我都会更新身体位置
_body->SetTransform(b2Vec2(self.position.x/PTM_RATIO,self.position.y/PTM_RATIO), 0);
问题是它们都被绘制了,但是精灵在正确的位置,而身体却没有;动作是连贯的
仅供参考,我在整个游戏中都使用 PTM_RATIO,所以这肯定不是问题