我刚开始学习AS3,因为我必须为作业创建一个简单的游戏,我有两个名为obj_laser和obj_enemy1的对象但是当我运行我创建的碰撞代码时,它会不断出现错误1009。这是一些代码,我知道它的凌乱。
stage.addEventListener(Event.ENTER_FRAME, runGame);
function runGame(event: Event): void {
// Fire Laser
LASERALARM++;
if (LASERALARM >= 10) {
var laser: obj_laser = new obj_laser
var laser2: obj_laser = new obj_laser
var flare: obj_flare = new obj_flare
var flare2: obj_flare = new obj_flare
laser.x = obj_spaceship.x + 12
laser.y = obj_spaceship.y
laser2.x = obj_spaceship.x - 12
laser2.y = obj_spaceship.y
addChild(laser);
addChild(laser2);
flare.x = obj_spaceship.x + 12
flare.y = obj_spaceship.y
flare2.x = obj_spaceship.x - 12
flare2.y = obj_spaceship.y
addChild(flare);
addChild(flare2);
LASERALARM = 0;
//移动激光
laser.addEventListener(Event.ENTER_FRAME, moveLaser);
function moveLaser(event: Event): void {
laser.y -= 5;
laser2.y -= 5;
}
}
// Spawn Enemies
ENEMYALARM++
if (ENEMYALARM >= (randomRange(100, 400))) {
var enemy1: obj_enemy1 = new obj_enemy1
enemy1.x = (randomRange(15, 165));
enemy1.y = -10;
addChild(enemy1);
ENEMYALARM = 0;
//Move Enemy
enemy1.addEventListener(Event.ENTER_FRAME, moveEnemy);
function moveEnemy(event: Event): void {
enemy1.y += 2;
}
if (laser.hitTestObject(enemy1)) {
parent.removeChild(laser);
parent.removeChild(enemy1);
}
}
答案 0 :(得分:0)
基本上,您正在尝试使用没有值的变量。
单击错误会将您带到代码中出现故障的位置。除此之外,开始在代码的不同位置追踪您的变量以尝试将其修改。