2014-07-26 52 views
0

我正在製作一款遊戲,而且我目前正忙於如何讓方法運行一段時間,關閉,然後讓另一種方法開始運行。目前我有:Spritekit如何運行一段時間的方法,然後再啓動另一個

[self spawn]; 

當場景設置。這裏是產卵方法:

-(void)spawn { 
int xMin = 0; 
int xMax = 460; 
CGPoint startPoint = CGPointMake(xMin + arc4random_uniform(xMax - xMin),320); 
[self performSelector:@selector(spawn) withObject:nil afterDelay:.20]; 
SKSpriteNode *blue = [SKSpriteNode spriteNodeWithImageNamed:@"whitecircle"]; 
blue.position = CGPointMake(startPoint.x,startPoint.y); 
blue.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:21.5]; 
blue.physicsBody.usesPreciseCollisionDetection = NO; 
blue.physicsBody.categoryBitMask = gainCategory; 
blue.physicsBody.contactTestBitMask = playerCategory; 
blue.physicsBody.dynamic = NO; 
[self addChild:blue]; 
SKAction *runBlue = [SKAction moveToY:0 duration:1.5]; 
SKAction *remove = [SKAction removeFromParent]; 
[blue runAction:[SKAction sequence:@[runBlue,remove]]]; 
} 

什麼,我想知道的是我怎樣才能使一定量的這個方法的時候運行,然後我怎麼可以啓動另一個方法這個完成之後。由於

+0

不能運行了一定量的時間的方法 - 但可以反覆調用的方法用給定的時間在給定頻率(固定或可變的)。這是你的意思嗎? – LearnCocos2D

+0

@ LearnCocos2D是的,這就是我應該問的。 – user3593148

回答

1

我覺得這是你在找什麼做:

// set duration to seconds you want to wait between spawns 
float duration = 1; 

SKAction *actionWait = [SKAction waitForDuration:duration]; 
SKAction *actionSpawn = [SKAction runBlock:^(void) 
{ 
    [self spawn]; 
}]; 

SKAction *actionSequence = [SKAction sequence:@[actionWait, actionSpawn]]; 
SKAction *actionRepeat = [SKAction repeatActionForever:actionSequence]; 

[self runAction:actionRepeat]; 

這是值得給予類引用SKAction良好的閱讀至少一次,這樣你就知道它的能力。

SKAction Class Reference

相關問題