0

I want to use CCTimer class for the Timer but I can't sort out. After I use to manually create a function for this but it seems not effective .

protected GameLayer(ccColor4B color)
{
    super(color);

            schedule(new UpdateCallback() {
        @Override
        public void update(float d) {
            countTime(d);
        }
      },0.99f);

}

public void countTime(float scr) {
    if(_label != null){
        this.removeChild(_label,true);
    }
    j=j-(int)scr;

    CGSize winSize = CCDirector.sharedDirector().displaySize();
    _label = CCLabel.makeLabel("Time Left :" + j, "Verdana", 20);
    _label.setColor(ccColor3B.ccGREEN);
    _label.setPosition(155f, winSize.height - 15);
    addChild(_label);

    if(j<=0){
        CCDirector.sharedDirector().pause();
    }

}

it run from 1 to the the point which i want to stop ... !!!

what should i do to use the CCTimer class to resolve this problem ?

Akarsh M
  • 1,629
  • 2
  • 24
  • 47

1 Answers1

1

CCTimer is available but I haven't tried this earlier but you can do this thing through Timer class :

Timer timer = new Timer();
timer.scheduleAtFixedRate( new TimerTask(){
public void run() {
    updateTimeLabel();
}




public void updateTimeLabel() {
        float time += 1;
        String string = CCFormatter.format("%02d:%02d", (int)(time /60) , (int)time % 60 );
        CCBitmapFontAtlas timerLabel = (CCBitmapFontAtlas) getChildByTag(TIMER_LABEL_TAG) ;
        timerLabel.setString(string);
}
  • I told you earlier that I haven't work on it. Sorry about that ,through this you can complete your work .. –  Jul 18 '13 at 04:58