我正在製作一個視差滾動地面的反應遊戲。我的敵人產卵計時器位於didMoveToView,現在出現我的問題。遊戲速度加快,但是我的產卵方法保持不變,所以如果敵人以相同的頻率產生,那麼它會很無聊。 下面是代碼:給定時器的替代產卵方法
//inside the didMoveToView
SKAction *addEnemRand = [SKAction performSelector:@selector(addRandomEnemy) onTarget:self];
SKAction *addEnemRandWait = [SKAction waitForDuration:2];
SKAction *addEnemRandAll = [SKAction sequence:@[addEnemRandWait, addEnemRand]];
SKAction *addEnemRandAllForever = [SKAction repeatActionForever:addEnemRandAll];
[self runAction:addEnemRandAllForever];
是否有人知道的方式來產卵敵人以適當的方式?
這是移動地面的代碼(有兩個)。也許它有可能將產卵速度與地面位置聯繫起來?:
-(void)addGround:(SKSpriteNode *)sprite withSpeed:(int)speed {
if (ground.position.x+ground.frame.size.width/2 < 0) {
ground.position = CGPointMake(self.size.width+ground.size.width/2, ground.size.height/2+1);
}
// movement
ground.position = CGPointMake(ground.position.x-speed, ground.position.y);
}
感謝您的幫助! (代碼在目標c請)
編輯:所以它似乎GamePlayKit可以幫助我,但我不知道如何實現它的產卵方法。我在互聯網上閱讀了一些教程,但它沒有幫助我。有人能幫我嗎 ?
這是絕對是一個很好看,但沒例如,我無法幫助我瞭解有關產卵到地面運動的問題。 – ccdev