facebook

Timer

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #341213 Reply

    hardsofft
    Member

    HI, i am doing a game consisting of different levels. how can i place a timer for each level with different times i.e., for Level1 8seconds, Level2 15seconds, Level 3 30seconds, etc. i got my code in which the user have the option to play a game using timer or not. its up to user and as i insert it in each page(Level), its overlapping and not working.

    
    <script>
        
        var CCOUNT = 8;
        
        var t, count;
        
        function cddisplay() {
            // displays time in span
            document.getElementById('timespan').innerHTML = "Time Left:" + count;
        };
        
        function countdown() {
            // starts countdown
            cddisplay();
            if (count == 0) {
              alert('time is up');
               phoneui.gotoPage('m1-HOMESCREEN','NONE');
               location.reload();                      
            } else {
                count--;
                t = setTimeout("countdown()", 1000);
            }
        };
        
        function cdpause() {
            // pauses countdown
            clearTimeout(t);
        };
        
        function cdreset() {
            // resets countdown
            cdpause();
            count = CCOUNT;
            cddisplay();
        };
        
    </script>
    
    <body onload="cdreset()">
    <span id="timespan"></span>
    <input type="button" value="Start" onclick="countdown()">
    <input type="button" value="Stop" onclick="cdpause()">
    <input type="button" value="Reset" onclick="cdreset()">
    </body>
    
    
    #341222 Reply

    Brandon
    Member

    Use the Javascript timing events to get better results:
    http://www.w3schools.com/js/js_timing.asp

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Timer

You must be logged in to post in the forum log in