所以我创建了一个体,并用精灵填充它。问题是,如果我对身体施加一个力,精灵会比身体高(我可以从debug_draw看到)。知道为什么会这样吗?
更新
- (void)tick:(ccTime) dt {
_world->Step(dt, 10, 10);
for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) {
if (b->GetUserData() != NULL) {
CCSprite *playerData = (CCSprite *)b->GetUserData();
playerData.position = ccp(b->GetPosition().x * PTM_RATIO,
b->GetPosition().y * PTM_RATIO);
playerData.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
}
}
}
以下是我在init方法中调用它的方法:
[self schedule:@selector(tick:)];
答案 0 :(得分:0)
获取User_Data的for循环现在不断重复,因此更新生物的位置会很困难..请在tick方法中移动精灵位置....
-(void) moveCreature
{
// Please use the position to set the directions. This is used to fall from upside down in Portrait mode
[spriteCreature setPosition:ccp(spriteCreature.position.x,spriteCreature.position.y-5)];
}
现在在init方法中安排精灵
-(id) init
{
if((self = [super init]))
{
// Create your World and other stuffs
[self schedule:@selector(moveCreature)];
}
return self;
}
上面的东西会把身体中的精灵摔倒......