A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [CS3] Timer help required!

  1. #1
    Junior Member
    Join Date
    Sep 2008
    Posts
    23

    Unhappy [CS3] Timer help required!

    Hi all,

    I've made a countdown timer for my game, once it reaches zero it goes to the next frame, thats all fine but my problem is this:

    if you complete the level before the time is up, how can i stop the timer and display the remaining time in the following frame. Also it would be nice if i could take the remaining time, multiply it by 10 and display that as a final score.

    This is the code i have for the time so you can see my method.

    Code:
    timer=120;
    countdown=function(){
    	timer--;
    	if (timer==0){
    		clearInterval(doCountdown);
    		_parent.nextFrame();
    	}
    }
    
    doCountdown=setInterval(countdown,1000);
    Thanks for any help

    Adam

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    1st use functions- they solve many design errors,
    that beeing said I would group your code in a function and capture the time when you start the interval and use that timeStamp to compute the time that elapsed starting from then.
    PHP Code:
    function startTimer(){
        
    _root.startTime getTimer();
        
    timer=120;
        
    countdown=function(){
            
    timer--;
            if (
    timer==0){
                
    clearInterval(_root.doCountdown);
                
    _parent.nextFrame();
            }
        }
        
        
    _root.doCountdown=setInterval(countdown,1000);
    }
    function 
    stopTimer(){
        
    clearInterval(_root.doCountdown);
        var 
    timeDifference = (getTimer() - _root.startTime)/1000;//in seconds
        
    trace("score: "+int(timeDifference*10)+" pts");
        
    _parent.nextFrame();


  3. #3
    Junior Member
    Join Date
    Sep 2008
    Posts
    23
    I don't fully understand the code i'm afraid,

    I tried putting that code into my game but the following happened: the dynamic text box within the game level just displays "_level0.instance39.timer" and in the following results screen it displays "0"

  4. #4
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    the first function did what you showed us here before (I assume you understood that code at least), except that it stores the current flash running time in a variable called _root.startTime

    the 2nd function (should be called when interrupting ) interrupts the interval,- calculates the time difference and traces it.

    I havent tested the code in flash so changes might be that you need to debug it but it looks ok to me.

  5. #5
    Member
    Join Date
    Oct 2008
    Posts
    49
    it works fine in flash for me

  6. #6
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    maybe he does not know how to use functions -_-

    in that case read the manual:
    http://www.adobe.com/support/flash/a...ionary373.html
    http://www.oman3d.com/tutorials/flash/intro_func_bc/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center