【问题标题】:Make my enemy move right and then left让我的敌人左右移动
【发布时间】:2014-04-12 15:13:07
【问题描述】:

你好闪存程序员, 我正在尝试完成一种让我的敌人向左移动一定数量的像素的方法,然后当它有时,我希望它以相反的方式移动。 所以如果enemy.x += 移动了20个像素。让它向相反的方向移动,然后让它向左移动。

所以您知道,在平台游戏中,您的敌人会左右移动。这就是我想要达到的目标。

但我的代码由于某种原因无法正常工作,因为计时器没有重置为 0。

我可以在代码方面获得一些帮助。

    private function goblinLoop(e:Event):void 
    {
        trace(nTimer);

        if (move)
        {
            nTimer = nTimer + 0.05;
            if (nTimer < 5)
            {
                this.x += speed;
            }   
            else
            {
                this.x -= speed;
                if (nTimer > 5)
                {
                    nTimer = 0;
                }
            }
        }
    }

【问题讨论】:

    标签: actionscript-3 flash


    【解决方案1】:

    问题出在代码中,我正在测试 if 语句和 flash 变得混乱,所以我不得不改变一件事,这是

    private function goblinLoop(e:Event):void 
    {
        trace(nTimer);
    
        if (move)
        {
            nTimer = nTimer + 0.05;
            if (nTimer < 5)
            {
                this.x += speed;
            }   
            else
            {
                this.x -= speed;
                if (nTimer > //this can't be 5, it's not logical, so it has to be 10)
                {
                    nTimer = 0;
                }
            }
        }
    }
    

    我希望这对其他人有帮助,你可以用它来左右移动你的角色

    如果您认为有一种有效的左右移动方式,请告诉我。谢谢你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      相关资源
      最近更新 更多