As3:子弹给我错误?

时间:2014-03-04 16:57:00

标签: actionscript-3 runtime-error movieclip addchild projectile

我有一个敌人类,它会在玩家身上产生子弹。

        private function fireBullet()
        {
            if(isFiring)
            {
            fire();
            }
        }

    public function fire():void
    {
        var bullet:Bullet = new Bullet(x, y, rotation);
        stage.addChild(bullet);
    }

在子弹课上:

package  {

import flash.display.MovieClip;
import flash.events.Event;

public class Bullet extends MovieClip {

    private var _root:MovieClip;
    private var isVanished:Boolean = false;

    public function Bullet(x:int, y:int, rotation:Number) 
    {
        this.x = x;
        this.y = y;
        this.rotation = rotation;

        _root = MovieClip(root);
        addEventListener(Event.ENTER_FRAME, loop);
    }

    private function loop (event:Event):void
    {           
        if(this.hitTestObject(_root.assassin.hitbox))
               {
                   _root.hitPoints -= 30;
                               }


        else
        {
            y-=Math.cos(rotation/-180*Math.PI)*(15);
            x-=Math.sin(rotation/-180*Math.PI)*(15);
        }

        if(this.x < 0 || this.x > _root.stageWidth || this.y > _root.stageWidth || this.y < 0)
        {
            removeChild(this);
            removeEventListener(Event.ENTER_FRAME, loop);
        }
    }
}

}

然而,当我开始游戏时,第23行出现1009错误,游戏因子弹甚至没有移动而迅速减速。

我也得到1063错误,期待3但是有0。

ArgumentError: Error #1063: Argumentblabla for Bullet(). Expected 3 but 0 were shown. ((translated))
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at Main()[C:\Venture Inc\Main.as:189]

这就是主要的样子

//Constructor
        public function Main()
        {

            addChild(container_staff);
            addChild(container_wall);

                  etc etc etc

1 个答案:

答案 0 :(得分:0)

ArgumentError: Error #1063: Argumentblabla for Bullet(). Expected 3 but 0 were shown. ((translated))

Bullet类构造函数有3个参数。更准确地检查你的代码,我认为你有类似的东西:

var bullet: Bullet = new Bullet();

您的代码也存在问题。每个项目符号都订阅了ENTER_FRAME。集中游戏,创建主循环,并从那里更新所有游戏角色(子弹,敌人等)。