【问题标题】:Flashdevelop As3 src\Enemy.as(28): col: 16 Error: Return value must be undefined. return false;Flashdevelop As3 src\Enemy.as(28): col: 16 错误:返回值必须未定义。返回假;
【发布时间】:2015-01-08 11:15:42
【问题描述】:

我目前正在为我的 uni 模块开发一款游戏,但似乎不知道如何解决这个问题。有人可以帮帮我吗?该游戏是 2D 平台游戏,我试图在敌人的生命值

这是我的敌人代码:

package  
{
    import flash.display.MovieClip;
    /**
     * ...
     * @author Umeer
     */
    public class Enemy extends MovieClip
    {
        public var health:int = 100;
        public function Enemy() 
        {
            this.graphics.beginFill(0xFF1100, 1);
            this.graphics.drawCircle(this.x, this.y, 25);
            this.graphics.endFill();
        }
        public function CheckObj(obj:Player,bullets:Array):void
        {
            if (Math.abs(obj.x - x) < obj.width / 2 + width / 2 && Math.abs(obj.y - y) < obj.height / 2 + height / 2)
                obj.health --;
            for (var i:int = 0; i < bullets.length; i++)
            {
                if (Math.abs(bullets[i].x - x) < width / 2 && Math.abs(bullets[i].y - y) < height / 2)
                    health -= 50;
            }
            if (health <= 0)
                return true;
            return false;
        }

    }

}

【问题讨论】:

    标签: actionscript-3 flashdevelop 2d-games


    【解决方案1】:

    您在函数中使用return false,并将返回值定义为void。 您应该将函数CheckObj 的签名更改为:

    public function CheckObj(obj:Player, bullets:Array):Boolean
    

    【讨论】:

    • 现在可以了,我从来没有想过这个,非常感谢!
    猜你喜欢
    • 2021-06-29
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多