更改Number Bug AS3的值

时间:2014-03-28 07:35:19

标签: actionscript-3 flash numbers flash-cs6

嘿大家所以我在这里遇到了一些麻烦。已经有一个小时了,无法找到解决方案。

所以我将一个名为_Bunny的影片剪辑添加到舞台上,如下所示:

        _Bunny = new mcBunny;
        stage.addChild(_Bunny);
        _Bunny.x = (stage.stageWidth / 2) - 225;
        _Bunny.y = (stage.stageHeight / 2) - 330;

现在这个_Bunny所做的是在一个循环中从右到左水平移动我在Enter_Frame事件监听器中设置的循环:

private function bunnyView():void 
    {
        _Bunny.x += nBunnySpeed;

        if (_Bunny.x >=(stage.stageWidth / 2) + 215)
        {
            _Bunny.gotoAndStop("leftView");
            nBunnySpeed--;

        }
        if (_Bunny.x <=(stage.stageWidth / 2) - 215)
        {
            _Bunny.gotoAndStop("rightView");
            nBunnySpeed++;
        }


    }

它的速度是nBunnySpeed,它等于5.现在,我有另一个函数,我试图将nBunnySpeed的值改为20 {{1像这样等于1:

nScore

但是产生的错误是兔子在屏幕右侧射击,这是&#34; + x&#34;无论我做什么,这总会发生。

任何人都可以看到我可能做错了吗?我不明白为什么会这样。请帮忙!

2 个答案:

答案 0 :(得分:1)

你在这个功能中做了什么

private function bunnyView():void 
{
    _Bunny.x += nBunnySpeed;

    if (_Bunny.x >=(stage.stageWidth / 2) + 215)
    {
        _Bunny.gotoAndStop("leftView");
        nBunnySpeed--;

    }
    if (_Bunny.x <=(stage.stageWidth / 2) - 215)
    {
        _Bunny.gotoAndStop("rightView");
        nBunnySpeed++;
    }
}

检查_Bunny是否在屏幕外。如果是这样,那么nBunnySpeed将是nBunnySpeed - 1.但是,自BunnySpeed = 20,它将是20 + 19 + 18 + 17,仍然是正确的。如果您要将其转为BunnySpeed = -BunnySpeed,它会立即反转并返回。

答案 1 :(得分:1)

你需要某种标志,表明难度已经更新。然后,当你调用updateDifficulty时,它首先检查是否真的需要现在更新速度,如果没有,它就会返回。但是,如果是,则更新兔子的速度并设置该标志,以便下次该功能不会改变兔子的速度。

var diffUpdated:Boolean=false;
private function updateDifficulty():void 
{
    if (diffUpdated) return; // here
    if (nScore >= 1)
    {
        //Increase Speed
        if (nBunnySpeed<0) nBunnySpeed=-20;
          else nBunnySpeed = 20; // retain the direction of bunny's movement
    }
    diffUpdated=true;
}

现在,无论何时你想要更新你的难度,你都会diffUpdated=false;并且瞧,兔子的速度将由此更新。但是,为此,您需要两个以上的速度级别,可能需要一个10级,一个50级,一个200级。

相关问题