mercredi 25 janvier 2017

I need a working pause and resume code on my project

I tried many of code so for pause and play to game but did not work many of them.

I got a moving object on stage also I have timer dynamic text.

I need a working pause and play code on my project.

Example my moving object

/*Fish 3 move*/
var balik3x:Number=7;
var balik3y:Number=Math.random()*15
 
stage.addEventListener(Event.ENTER_FRAME,h3);
function h3(oly:Event) {
balik3.x+=balik3x;
balik3.y+=balik3y;
if ((balik3.x>=stage.stageWidth-balik3.width/2)|| (balik3.x <= balik3.width/2 )) {
    balik3x*=-12;
}
if ((balik3.y>=stage.stageHeight-balik3.height/2)|| (balik3.y <= balik3.height/2 )) {
    balik3y*=-1;
}
}
balik3.mouseEnabled = false;

My timer code

time.text="0:10";
var dispSecs=09;
var dispMins=0;
 
var timerInterval=setInterval(countDown,1000);
var control:Timer = new Timer(1000,0)
control.addEventListener(TimerEvent.TIMER, keko)
control.start();
 
function keko (evt:Event):void{

if(dispMins <1 && dispSecs <1 )
{
timeisup.visible = true;
timeisup.play();
}
}
 
function countDown()
{
dispSecs--;
if (dispMins == 0 && dispSecs == 0)
{
clearInterval(timerInterval);
}
else if (dispSecs == 0)
{
dispSecs = 59;
if (dispMins > 0)
{
dispMins--;
}
}
time.text = prependZero(dispMins) + ":" + prependZero(dispSecs);
}  
 
function prependZero(num)
{
if(num<10)
{
num=""+num;
}
return(num);
} 

The last code I tried.But it's not work exactly.

pause1.addEventListener(MouseEvent.CLICK, pauseGame);
function pauseGame(event:MouseEvent):void{
 stage.frameRate = 0;
}
play1.addEventListener(MouseEvent.CLICK, resumeGame);
function resumeGame(event:MouseEvent):void{
stage.frameRate = 15;
}

Aucun commentaire:

Enregistrer un commentaire