【发布时间】:2014-08-30 07:10:00
【问题描述】:
我的游戏中有一个玩家,它有两种状态,飞行和下降。他们每个人都有一个图像: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:无法创建物理实体。
【问题讨论】:
-
检查两张图片是否都已加载,即self.player.texture不能为nil
-
它不是nil,实际上它甚至在游戏中改变了纹理,但不改变物理体,它在屏幕上显示为静态图像。
-
上面的代码是在update方法中实现的吗?
-
是的,是在update方法中实现的。