Actionscript 3 As3:子弹给了我错误?
我有一个敌人职业,可以向玩家发射子弹Actionscript 3 As3:子弹给了我错误?,actionscript-3,runtime-error,movieclip,addchild,projectile,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);
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);
}
}
}
}
这就是main的样子
//Constructor
public function Main()
{
addChild(container_staff);
addChild(container_wall);
etc etc etc
Bullet类构造函数有3个参数。请更精确地检查代码,我认为您有如下内容:
var bullet: Bullet = new Bullet();
你的代码也有问题。每个项目符号都订阅ENTER_帧。集中您的游戏,创建主循环,并从那里更新所有游戏参与者(子弹、敌人等)。我觉得我们缺少了一些背景。你能把所有的代码都贴出来吗?代码太多了,所以我真的不知道还能贴什么。。我注意到,如果删除除(_root.hitPoints-=30;)之外的所有代码,仍然会出现错误。似乎这个错误意味着_root。如果您不确定从哪里开始,那么最好的解决方法是添加一些跟踪语句,查看在错误发生之前执行哪些跟踪语句,一旦发现错误可能在哪里,就开始注释行,查看是否可以消除错误。正如我所说,如果我只有私有函数loop(event:event):void{{u root.hitPoints-=30;},它仍然会给我错误。它必须与_root相关。(虽然定义正确:private var\u root:MovieClip;然后\u root=MovieClip(root);在构造函数中。当然可以,但我看不到它的定义位置。假设没有显示的部分是正确的,那么您的所有代码看起来都很好。如果您遇到错误,它们显然是错误的?错误看起来像是您在调用方法/构造函数时忘记添加一些参数
ArgumentError: Error #1063: Argumentblabla for Bullet(). Expected 3 but 0 were shown. ((translated))
var bullet: Bullet = new Bullet();