• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
 How to create flash game level timer tutorial
 
In this tutorial I'll explain how to create Flash game level timer mechanism. Code I'm using hereis very simple, it's not something you should use in your final product. Code is ActionScript2.0.Sample FLAis Flash 8 file and it demonstrates how timer works.
Graphic elements are simple to create. We have startBtn movie clip in Library with 'startlevel' instanceon Stage. Another graphic element is dynamic single-line text field with instance name 'timeleft'. Whenyou start sample file situation our text field shows time left in minutes and seconds. Start level button isvisible and waiting for click. When that happens button get zero alpha (should be moved from Stage)and countdown timer start to work.
 
 
Some formating is done, so numbers are displayed like they should, instead of 1:1 we have 1:01etc. Timer resets when reach 0:00 and start level button is visible again, waiting for action. Inreal time situation, you can have different level durations for different levels. That means youshould replace maxCount variable with Array of different intervals each represents duration of levels in seconds.Here is the code:
var count:Number = 0;var maxCount:Number = 75;var intervalID:Number;var timerStarted = false;var temp:Number;if(maxCount < 60) {timeleft.text = "0 : "+maxCount;} else {if((maxCount%60)<10) {timeleft.text = Math.floor((maxCount/60))+" :0"+(maxCount%60);} else {timeleft.text = Math.floor((maxCount/60))+" : "+(maxCount%60);}}startlevel.onRelease = function() {if(!(timerStarted)) {intervalID = setInterval(_root, "hronos", 1000);timerStarted = true;this._alpha = 0;}}function hronos():Void {if(count < maxCount) {count++;temp = maxCount - count;if(temp < 60) {if(temp < 10) {timeleft.text = "0 : 0"+temp;} else {
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...