How to pause a Timer??
Im finishing of one of my many projects, I HATE UI!! and i read about 7 things to avoid on how to make a crappy game, and one of them was a pause button , i managed to add all the other things in, but im absolutely stumped on a pause button. I read one tutorial, which didn't really help. it was talking about a main game loop and all that crap that just baffled me. i did try it though, and i did not get any errors, just ALOT of laf, becaus what i did was put all my constructor code into the 'update' function, so it was running my spawn enemies every frame ect. but the i realised all i need to do is pause my timer, because thats the only thing that really needs to be done right? i read somewhere about pausing timers with getTimer, but that confused me as no where was really explaining the concept just giving the answer really. Can someone help me please ??
here is my timer:
public function setCrates()
{
DropCrate = new Timer(10000+Math.random()*10000,1);
DropCrate.addEventListener(TimerEvent.TIMER_COMPLETE, newCrate);
DropCrate.start();
}
public function newCrate(Event:TimerEvent)
{
var StartPosition:Number = Math.random() * 90 + 10;
// create plane
var c:Crate = new Crate(StartPosition);
addChild(c);
Crates.push(c);
setCrates();// set time for next crate;
}
this is the game loop thing i was talking about:
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class Main extends MovieClip
{
private var isPaused:Boolean; // This is the variable that holds our paused/unpaused state
public function Main()
{
// Unpause the game:
isPaused = false;
// Add an event listener to keep an eye (ear?) on the built-in ENTER_FRAME event.
// Every time Flash processes a frame tick, doMasterGameLoop will execute:
addEventListener(Event.ENTER_FRAME, doMasterGameLoop);
}
private function doMasterGameLoop(e:Event = null):void
{
// This is the main game loop that does all the work. It's the
// "gateway" to everything our game does. If the game is paused,
// nothing in the game loop happens.
if (!isPaused)
{
update();
draw();
}
}
private function update():void
{
// Tweak all your numbers and math stuff here
}
private function draw():void
{
// Update all your graphics here
}
}
}