我是 Cocos2d 的初学者,我想在硬币精灵离开屏幕后立即显示硬币精灵,延迟 5 秒。所以这就是我在我的主要游戏层中写的连续添加 7 个硬币的内容:
- (void)coinSidewaysRowOne {
if (coinSide1 == FALSE)
{
coinSide1 = TRUE;
NSLog(@"coinSide1 = TRUE");
int originalX = 500;
for(int i = 0; i < 8; i++)
{
CCSprite *coinHorizontal = [CCSprite spriteWithFile:@"bubble.png"];
coinHorizontal.position = ccp(originalX, 150);
originalX += 20;
[self addChild:coinHorizontal];
[coinArray addObject:coinHorizontal];
}
}
}
然后,在我的 updateRunning 方法中我添加了这个,所以当硬币在屏幕外产生时,它们向左移动并消失:
// Move coins off the screen and make them move away
for (CCSprite *coin in coinArray) {
// apply background scroll speed
float backgroundScrollSpeedX = [[GameMechanics sharedGameMechanics] backGroundScrollSpeedX];
float xSpeed = 1.09 * backgroundScrollSpeedX;
// move the coin until it leaves the left edge of the screen
if (coin.position.x > (coin.contentSize.width * (-1)))
{
coin.position = ccp(coin.position.x - (xSpeed*delta), coin.position.y);
}
}
所以现在,当我运行它时,硬币从右侧移入并从左侧移出屏幕。我该如何做到这一点,以便当硬币向左移动并离开屏幕时,有五秒钟的延迟,然后让新硬币像原来一样从右侧回到屏幕上。
谢谢!