Pregunta

I'm planning to make a tug of war game and I have difficulty in this part... The game is the user have to rapidly click the button to win the game. I made it in numbers 1 click = +1 and at the same time with or without clicking the value of controller decreases by 0.5

thanks for the help

var controller = 10;
blocker.visible = false;

function decreasing(){
controller = controller - 0.5;
}

decreasing();

pushBtn.addEventListener(MouseEvent.CLICK, theGame);

function theGame (e:MouseEvent): void {
controller = controller + 1;

if ((controller <= 5) || (controller >=9)){
    ropeMc.gotoAndPlay("down1");
}

if ((controller <= 1) || (controller >=4)){
    ropeMc.gotoAndPlay("down1");
}

if ((controller >= 15) || (controller <=19)){
    ropeMc.gotoAndPlay("up1");
}

if ((controller >= 20) || (controller <=29)){
    ropeMc.gotoAndPlay("up2");
}

if (controller >= 30){
    ropeMc.gotoAndStop(20);
    blocker.visible = true;
}

}

¿Fue útil?

Solución

Try this,

var controller = 10;
    blocker.visible = false;


stage.addEventListener(Event.ENTER_FRAME, decreasing);   
pushBtn.addEventListener(MouseEvent.CLICK, theGame);

function theGame (e:MouseEvent): void {
controller = controller + 1;
changeState();

}


function decreasing(e:Event){
controller = controller - 0.5;
}

function changeState():void{

if ((controller <= 5) || (controller >=9)){
    ropeMc.gotoAndPlay("down1");
}

if ((controller <= 1) || (controller >=4)){
    ropeMc.gotoAndPlay("down1");
}

if ((controller >= 15) || (controller <=19)){
    ropeMc.gotoAndPlay("up1");
}

if ((controller >= 20) || (controller <=29)){
    ropeMc.gotoAndPlay("up2");
}

if (controller >= 30){
    ropeMc.gotoAndStop(20);
    blocker.visible = true;
    stage.removeEventListener(Event.ENTER_FRAME, decreasing); 
}
}

Hope it helps.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top