[英]SpriteKit PhysicsBody: Could not create physics body
我的游戏中有一个玩家,它有两个状态飞行,下降。 他们每个人都有一个图像:player_flying,player_falling相应的。 我也使用物理身体来检测碰撞。 当我使用一个纹理时它完全正常运行。 但是当我尝试在不同的条件下使用不同的纹理时,它会在日志中显示错误。 我这样想:
if (self.player.physicsBody.velocity.dy > 30) {
self.player.texture = [SKTexture textureWithImageNamed:@"player_flying"];
self.player.physicsBody = [SKPhysicsBody bodyWithTexture:self.player.texture
size:self.player.size];
}
else
{
self.player.texture = [SKTexture textureWithImageNamed:@"player_falling"];
self.player.physicsBody = [SKPhysicsBody bodyWithTexture:self.player.texture
size:self.player.size];
}
错误是:
2014-08-30 12:55:47.515 kalabaska [1569:50535] PhysicsBody:无法创建物理体。
感谢0x141E,我发现我的纹理周围有一些白色的狗屎,在我删除它之后,一切都开始起作用了。 现在我想知道如何在我的纹理周围隐藏描边,代表我的物体。
您不应该以更新速率更改播放器的纹理和物理主体(最多每秒60次)。 您应该只在需要时更改它们。 这是一个如何做到这一点的例子:
if (self.player.physicsBody.velocity.dy > 30) {
// Change texture/body only if not already flying
if (!isFlying) {
self.player.texture = [SKTexture textureWithImageNamed:@"player_flying"];
self.player.physicsBody = [SKPhysicsBody bodyWithTexture:self.player.texture
size:self.player.size];
isFlying = YES;
}
}
else
{
// Change texture/body only if not already falling
if (isFlying) {
self.player.texture = [SKTexture textureWithImageNamed:@"player_falling"];
self.player.physicsBody = [SKPhysicsBody bodyWithTexture:self.player.texture
size:self.player.size];
isFlying = NO;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.