2014-12-05 86 views
0

我有一個球開始衝動,但我希望它在等待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]; 

回答

2

等待僅適用於其他操作。

如果您想在等待後應用衝動,則需要將其作爲動作添加到塊中。一旦你有你的等待行動,以及你的應用脈衝行動,那麼我們把它們放在一起。合理?

//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 
    ]]];