2014-03-31 19 views

回答

1

你可以用SKActions做到這一點。例如...

SKAction *wait = [SKAction waitForDuration:1.0f]; 
SKAction *sequence = [SKAction sequence:@[[SKAction performSelector:@selector(methodToFire:) onTarget:self], wait]]; 
SKAction *repeat = [SKAction repeatActionForever:sequence]; 
[self runAction:repeat]; 


- (void)methodToFire { 
... 
} 
2

如果你想要做什麼遊戲邏輯關係,這是很容易操縱的更新方法做你想做什麼。

-(void)update:(CFTimeInterval)currentTime 
{ 
    /* Called before each frame is rendered */ 
    // Handle time delta. 
    // If we drop below 60fps, we still want things to happen at the same realtime rate. 

    CFTimeInterval timeSinceLast = currentTime - lastUpdateTimeInterval; 
    lastUpdateTimeInterval = currentTime; 

    [self updateWithTimeSinceLastUpdate:timeSinceLast]; 

} 

- (void)updateWithTimeSinceLastUpdate:(CFTimeInterval)timeSinceLast 
{ 

    lastEventInterval += timeSinceLast; 
    //this is the part that will function like a timer selector and run once a second. 
    if (lastEventInterval > 1) 
    { 
     lastEventInterval = 0; 
     //do whatever you want to do once a second here 
    } 
} 
+0

出於好奇,爲什麼CFTimeInterval而不是NSTimeInterval? – Roecrew

+0

這是用於它們傳遞到更新方法的參數是什麼蘋果,所以它是我在其中使用。我也用NSTimeIntervals對於沒有問題類似的事情。我實際上不是在兩者之間的差異特別明顯 - 他們似乎都只是typedef定義雙打。 – webbcode

相關問題