The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 1:57 am

Forum rules


IMPORTANT

This Forum is for Flash related questions ONLY! Do not ask questions about spriting, Game Maker, Photoshop, or anything else not related to Flash.



 [ 2 posts ] 
[Question, AS3] Timers??? 
Author Message
Site Moderator
User avatar

Joined: Fri May 22, 2009 3:44 pm
Posts: 4156
Location: saying things with posed looks
Gender: Anime Girl
Skype: Snail's Legacy
Currently Playing: umib and unib
Waifu: SNAIL
Ok so I know this forum is dead but I need help here


How do I actually go about making a timer? A project I'm working on is only half done and it's lagging like hell when I try to implement a timer.

Then I look at a content packed game like ssf2 and the timers are working flawlessly.
The timer by itself is fine, but adding any type of content will make it lag.

How I went about it is I call this one function every second, make it update the time, and then save it to a shared object so it can resume from the time played next time you run it. basically, I'm trying to make a "Time Played" Viewer thingy.

The code below shows my timer code and how I went about it.


code: show
Code:
private function timerTickHandler(Event:TimerEvent):void
      {
         toTimeCode();
      }
      
      private function toTimeCode():void // Thanks to the function above, this runs every second
      {
         if (isNaN(milli)) // If the milliseconds are not defined yet...
         {
            savedata.data.profile.gameTime.milli = 0; //...Reset the milliseconds to 0. This continues for seconds mins and hours
            if (isNaN(secs))
            {
               savedata.data.profile.gameTime.secs = 0;
               if (isNaN(mins))
               {
                  savedata.data.profile.gameTime.mins = 0;
                  if (isNaN(hrs))
                  {
                     savedata.data.profile.gameTime.hrs = 0;
                  }
               }
            }
         }
         else
         {
            milli = milli + 1; // From here downward, the time is updating and saving automatically
            if (milli == 10)
            {
               secs = secs + 1;
               milli = 0;
            }
            if (secs == 60)
            {
               secs = 0;
               mins = mins + 1;
            }
            if (mins == 60)
            {
               mins = 0;
               hrs = hrs + 1;
            }
            savedata.data.profile.gameTime.milli = milli;
            savedata.data.profile.gameTime.secs = secs;
            savedata.data.profile.gameTime.mins = mins;
            savedata.data.profile.gameTime.hrs = hrs;
            savedata.flush();
            updateNumbers();
         }
      }
      
      private function updateNumbers():void // This function just displays the updated time.
      {
         secStr = (String(secs).length != 2) ? "0" + secs : secs;
         minStr = (String(mins).length != 2) ? "0" + mins : mins;
         
         if (statsScr)
            statsScr.totaltime.text = hrs + ":" + minStr + ":" + secStr + "." + milli;
      }


I REALLY NEED A PROGRAMMER RIGHT ABOUT NOW

google and I aren't friends at the moment

_________________
Image

Image Image Image

early 2k nostalgia mode


Wed Jan 22, 2014 1:33 am

Joined: Sat Apr 16, 2011 7:39 pm
Posts: 1451
Location: Enjoying Life
Country: United States (us)
Gender: Male
Skype: sazhchocobo
Currently Playing: League of Legends, Killing Floor 2, Overwatch
Waifu: Cleod9
I always PM'd Cleod when I needed help in AS3. He actually responds so yeah

_________________
Trying my best to better myself as a programmer! Please visit my programming blog, any and all tips are welcome!: https://conceptsexplained.wordpress.com


Sat Jan 25, 2014 9:19 pm
Display posts from previous:  Sort by  
 [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.