0
我有一个在玩家身上产生子弹的敌人。As3:子弹给我错误?
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
我觉得我们错过了一些上下文。你能发布所有的代码吗? –
有很多的代码,所以我真的不知道还有什么可以发布的。 我注意到,如果我删除除(_root.hitPoints - = 30;)之外的所有代码,我仍然会收到错误消息。 看起来好像错误意味着_root。一片空白? – user3123633
那么,如果您不确定从何处开始进行故障排除,最好的方法是添加一些跟踪语句,查看在错误发生之前哪些语句被执行,以及一旦找到错误可能会在哪里开始注释行看看你是否可以让错误消失。一旦你发现修复它应该很容易。 –