我有一個SpriteNode
,它受y軸上的重力影響,可以通過x軸上的加速度計移動。我的場景中還有一個邊框(SKPhysicsBody
),它將我的節點保留在場景中。現在的問題是,我的節點在執行由加速度計引起的SKAction
時忽略了邊框。與PhysicsBody碰撞時停止SKAction
我對X移動/加速度計和其動作代碼:
birdNode
是我SpriteNode
float destX = 0.0;
float currentX = birdNode.position.x;
BOOL shouldMove = NO;
if (data.acceleration.x < -0.1) {
destX = currentX + (data.acceleration.x * playerXSpeed);
shouldMove = YES;
}
else if (data.acceleration.x > 0.1) {
destX = currentX + (data.acceleration.x * playerXSpeed);
shouldMove = YES;
}
if (shouldMove) {
if (birdNode.position.x + destX < self.frame.size.width || birdNode.position.x - destX > 0) {
SKAction *moveBird = [SKAction moveToX:destX duration:0.1];
[birdNode runAction:moveBird];
}
}
變量「data.acceleration.x」和「playerXSpeed」代表什麼? – sangony
data.acceleration.x是加速度計和playerXSpeed設定的速度值,它設爲80 –