-1

我是 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 方法中我添加了这个,所以当硬币在屏幕外产生时,它们会向左移动并消失:

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);
        }
        **// This is where I am trying to make the CCSprite coin reappear** 
        else
        {
            [self performSelector:@selector(showSpriteAgain:) withObject:coin afterDelay:5.0f];
        }
    }

然后我添加了这个方法:

-(void) showSpriteAgain:(CCSprite *)coin{
    CGSize screenSize = [[CCDirector sharedDirector] winSize];
    coin.position = ccp(coin.position.x-screenSize.width,coin.position.y);
}

但是硬币在 5 秒后仍然没有重新出现。难道我做错了什么?谢谢。

4

1 回答 1

1

showSpriteAgain 函数的变化:

-(void) showSpriteAgain:(CCSprite *)coin{
    CGSize screenSize = [[CCDirector sharedDirector] winSize];
    coin.position = ccp(coin.position.x + screenSize.width,coin.position.y);
}

我所做的是它从右向左移动所以我们必须把它放回右边所以我们必须添加screennSize.width,

于 2013-07-19T06:07:24.370 回答