我有一个向玩家发射子弹的敌人类。
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