我有一个球,开始一时冲动,但我希望它等3秒才能这样做。我把这段代码认为它可以解决问题,但它没有用。
//add sprite to scene
[self addChild:ball];
SKAction *wait = [SKAction waitForDuration:3];
[self runAction:wait];
//create vector
CGVector myVector = CGVectorMake(10, 25);
//apply vector to ballphysics body
[ball.physicsBody applyImpulse:myVector];
答案 0 :(得分:2)
等待仅适用于其他操作。
如果您想在等待后应用您的冲动,则需要将其作为动作添加到块中。一旦你有了等待动作和applyImpulse动作,我们就把它们组合成一个序列。有意义吗?
//add sprite to scene
[self addChild:ball];
SKAction *wait = [SKAction waitForDuration:3];
SKAction *applyImpulse = [SKAction runBlock:^{
//create vector
CGVector myVector = CGVectorMake(10, 25);
//apply vector to ballphysics body
[ball.physicsBody applyImpulse:myVector];
}];
[self runAction:[SKAction sequence:@[
wait,
applyImpulse
]]];