我试图让我的 SKSpriteNodes 永远以恒定的速度移动,即使在碰撞之后也是如此。我已将重力设置为 0,摩擦设置为 0,线性和角度阻尼设置为零,但 Sprites 仍然缓慢减速到零速度。我怎样才能让他们继续前进?
根据下面的答案,这是我尝试过的:编辑下面的代码有效!我只需要检查节点是否比限制慢并加快它们的速度。
[self enumerateChildNodesWithName:kBallName usingBlock:^(SKNode *node, BOOL *stop)
{
SKSpriteNode *ball = (SKSpriteNode *)node;
if (ball.physicsBody.velocity.dx < 0) {
if (ball.physicsBody.velocity.dx > -50)
ball.physicsBody.velocity = CGVectorMake(-50, ball.physicsBody.velocity.dy);
}
if (ball.physicsBody.velocity.dx > 0) {
if (ball.physicsBody.velocity.dx < 50)
ball.physicsBody.velocity = CGVectorMake(50, ball.physicsBody.velocity.dy);
}
if (ball.physicsBody.velocity.dy < 0) {
if (ball.physicsBody.velocity.dy > -50)
ball.physicsBody.velocity = CGVectorMake(ball.physicsBody.velocity.dx, -50);
}
if (ball.physicsBody.velocity.dy > 0) {
if (ball.physicsBody.velocity.dy > 50)
ball.physicsBody.velocity = CGVectorMake(ball.physicsBody.velocity.dx, 50);
}
}];