我可以看到 here如何使用 update() 函数来监视 SKNode 上的“位置”等属性,但我不知道如何知道 [node.physicsBody applyImpulse:vector]
等方法已完成。
-(void)someMethod {
_monitorOn = YES;
[_node.physicsBody applyImpulse:CGVectorMake(10,10)];
}
-(void)update:(CFTimeInterval)currentTime {
if( _monitorOn == YES ) {
NSLog(@"node position: %f,%f", _node.position.x, _node.position.y);
}
// When will this be turned off?
}
最佳答案
检查applyImpulse的效果是否完成有两种方法:
if (_node.physicsBody.resting) {
// Node is at rest, do something
}
您经常会发现 resting 属性从未设置,因为您的 sprite 移动非常缓慢(尤其是对于圆形节点)。因此,最好检查速度是否接近于零。
static inline CGFloat speed(const CGVector v)
{
return sqrtf(v.dx*v.dx+v.dy*v.dy);
}
if (speed(_node.physicsBody.velocity) < kSmallValue) {
// Node is moving very slowly, do something
}
关于ios - SpriteKit : How can I determine when methods like applyImpulse on a physicsbody are done?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25388324/