Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6865681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:05:03+00:00 2026-05-27T03:05:03+00:00

please can anyone show me how to implement a countdown timer for starting a

  • 0

please can anyone show me how to implement a countdown timer for starting a game in cocos2d for the iPhone.

What I mean is that on pressing “play” a new scene comes up with the numbers “3”, “2”, “1” displayed and then the word “GO!”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:05:04+00:00Added an answer on May 27, 2026 at 3:05 am

    From “cocos2d Best Practices”:

    Try NOT to use Cocoa’s NSTimer. Instead use cocos2d’s own scheduler.

    So this is example of using cocos2d’s scheduler to animate your label, even with some effect.

    In @interface:

    int timeToPlay;
    CCLabelTTF * prepareLabel;
    CCLabelTTF * timeoutLabel;
    CCMenu *menu;
    

    In init:

    timeToPlay=4;
    
    CGSize s = [CCDirector sharedDirector].winSize;
    prepareLabel = [CCLabelTTF labelWithString:@"Prepare to play!" fontName:@"Marker Felt" fontSize:40];
    prepareLabel.position = ccp(s.width/2.0f, 150);
    
    timeoutLabel = [CCLabelTTF labelWithString:@"3" fontName:@"Marker Felt" fontSize:60];
    timeoutLabel.position = ccp(s.width/2.0f, 90);
    
    [self addChild:prepareLabel];
    [self addChild:timeoutLabel];
    
    timeoutLabel.visible=NO;
    prepareLabel.visible=NO;
    
    ...
    CCMenuItem *Play = [CCMenuItemFont itemFromString:@"PLAY" 
                                               target:self 
                                             selector:@selector(aboutToPlay:)];
    ...
    

    aboutToPlay:

    -(void) aboutToPlay: (id) sender {
        [self removeChild:menu cleanup:YES];
        timeoutLabel.visible=YES;
        prepareLabel.visible=YES;
        [self schedule: @selector(tick:) interval:1];
    }
    

    And tick:

    -(void) tick: (ccTime) dt
    {
        if(timeToPlay==1) [self play];
        else {
            timeToPlay--;
            NSString * countStr;
    
            if(timeToPlay==1)
            countStr = [NSString stringWithFormat:@"GO!"];
            else
            countStr = [NSString stringWithFormat:@"%d", timeToPlay-1];
    
            timeoutLabel.string = countStr;
    
            //and some cool animation effect
            CCLabelTTF* label = [CCLabelTTF labelWithString:countStr fontName:@"Marker Felt" fontSize:60];
    
            label.position = timeoutLabel.position;
            [self addChild: label z: 1001];
            id scoreAction = [CCSequence actions:
                                [CCSpawn actions:
                                  [CCScaleBy actionWithDuration:0.4 scale:2.0],
                                  [CCEaseIn actionWithAction:[CCFadeOut actionWithDuration:0.4] rate:2],
                                  nil],
                                [CCCallBlock actionWithBlock:^{
                                  [self removeChild:label cleanup:YES];
                                }],
                                nil];
            [label runAction:scoreAction];
    
        }
    
    }
    

    Play:

    -(void) play {
        [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInL transitionWithDuration:0.4 scene:[GamePlay node]]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please can anyone one point me to a good tutorial that helps me to
I speak about josh smith article. can anyone show me please how the CustomerView.xaml
can anyone please show me an example about using regex (regex.h) in C/C++ to
Please can anyone show me how to convert a .java to UML diagram under
Can anyone please show me a specific example of a Symfony2 form entity update?
Can anyone please help me. I have developed macro that keeps track of huge
I need to update jquery1.3.2 to jquery1.4 (in Asp.net MVC). Please can anyone tell
can anyone please suggest a good code example of vb.net/c# code to put the
Can anyone please tell me if Certifying Authorities (CAs) are allowed to make modifications
Can anyone please provide a link to download the .NET 3.5 SDK? I checked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.