我怎么能不断减少一些在AS3

问题描述:

我打算做的战争游戏了拉锯战,我在这部分有困难......这场比赛是用户已快速点击按钮来赢得比赛。我做到了用数字1点击= + 1,并在同一时间有或没有点击的控制器下降0.5值

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

感谢您的帮助

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

}

试试这个,

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.