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 7517115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:20:39+00:00 2026-05-30T01:20:39+00:00

I am trying to make a timer for my game that counts down from

  • 0

I am trying to make a timer for my game that counts down from a number, let’s call it 100. I am following the cocos2d best practices, and therefore I am not using a NSTimer. What I am looking to do is that every second, I want to numbers of this timer to change. I could probably find a way to do it using a spritesheet with all of the numbers from 100-0, but I know there is a way to do it using just the numbers 0-9 and their pictures.

This is the code that I am using, with the corresponding -(void)

    [self schedule: @selector(tick:)];
    [self schedule: @selector(tick2:) interval:1];

All in all, I would like to know how to make it count down from 100, but also to know how to make those ticks decrease the value by 1 every second.

  • 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-30T01:20:41+00:00Added an answer on May 30, 2026 at 1:20 am

    Initialize an integer variable that will keep your countdown value:

    int count = 100;
    

    You will want to keep a label (CCLabelBMFont etc) to display this count value. I recommend Glyph Designer (or Hierro if you want something free) to generate the 0 to 9 cocos2D-compatible font bitmaps, which you can then use in your CCLabelBMFont:

    CCLabelBMFont* countLabel = [CCLabelBMFont labelWithString:@"0" fntFile:@"myFont.fnt"]; 
    

    Next, schedule a single tick function that will fire every second:

    [self schedule: @selector(tick:) interval:1];
    

    This tick function decrements count by 1 each time it is called. Also, add the condition that if count has reached 0, it will unschedule itself:

    -void tick:(ccTime) dt
    {
        count --; // decrement count by 1 each time this function is called
        if (count == 0)
            [self unschedule: @selector(tick:)];      
    }
    

    And finally, in your main update loop (or even in the tick function itself after you decrement your count), you can update and redraw this label with the latest value each time:

    [countLabel setString:[NSString stringWithFormat:@"%i", count]];
    

    All the best.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Im trying to make a game for the iPhone that has background music. So
I'm trying to make a little rock paper scissors game. for that I've written
I am trying to make a small game like app that has some interaction,
I am trying to make a game object that can be made semitransparent during
I'm trying to make a little game that will first show the player a
I'm trying to make a timer in c++. I'm new to c++. I found
Im trying to make an 2D online game (with Z positions), and currently im
I'm trying to make an easy side scrolling game just to learn the ropes
I've been trying to make a little simple game just to test my logics,

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.