how can i continuously decrease a number in as3

坚强是说给别人听的谎言 提交于 2019-12-13 04:24:43

问题


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;
}

}


回答1:


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.



来源:https://stackoverflow.com/questions/20512604/how-can-i-continuously-decrease-a-number-in-as3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!