Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa noite pessoal!
Venho mais uma vez solicitar a ajuda de vocês que sempre auxiliam aos que precisam.
Bem, estou desenvolvendo um jogo para o portal da empresa onde atuo, porém, estou numa situação um pouco complicada. Preciso controlar eventos do tiro e da colisao entre o tiro e o inimigo. Consegui chegar ao resultado que quero, porém, com um erro.
Erro: ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at Megamania_fla::MainTimeline/enterFrameHandler()
O erro citado acima, ocorre toda vez que o tiro passa pelo local anterior onde estava o inimigo.
// criando os inimigos
var enemyPack:Array = new Array(new Array(), new Array(), new Array(), new Array(), new Array());
for (var i:int = 0; i < qntEnemy; i++) {
for (var j:int = 0; j<3; j++) {
enemyPack[i][j] = new enemy1_mc();
enemyPack[i][j].x = i * 120;
enemyPack[i][j].y = j * 30;
addChild(enemyPack[i][j]);
enemyIsPlaying = true;
enemyIsNotPlaying = false;
}
}
// verificando evento de tiro
stage.addEventListener(KeyboardEvent.KEY_UP, shotHandler);
function shotHandler(event:KeyboardEvent):void {
if (isNotShooting) {
if (event.keyCode == Keyboard.SPACE) {
addChild(shot1);
swapChildren(shot1, shipClip);
shot1.x = shipClip.x;
shot1.y = shipClip.y;
isShooting = true;
isNotShooting = false;
}
}
}
// checando colisao com a nave e limite do tiro para o stage
// controls the objects moves, colissions and others.
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(ev:Event):void {
// controls shot1 moves when SPACE key is pressed.
if (isShooting) {
shot1.y-=sSpeed;
if (shot1.y < stageHeightLimit) {
removeChild(shot1);
isNotShooting = true;
isShooting = false;
}
// controls shot1 moves when collides with a enemy ship.
// CORRIGIR O PROBLEMA APÓS A REMOÇÃO ONDE FICA UM ESPAÇO VAZIO
for (var i:int = 0; i < qntEnemy; i++) {
for (var j:int = 0; j<3; j++) {
if (shot1.hitTestObject(enemyPack[i][j])) {
//trace(i +"");
//trace(j +"");
removeChild(enemyPack[i][j]); // onde o problema ocorre
enemyIsPlaying = false;
enemyIsNotPlaying = true;
removeChild(shot1);
isNotShooting = true;
isShooting = false;
}
}
}
}
}
Agradeço quem puder me ajudar, ou aquele q tentar.
Tenham todos uma boa noite.
Carregando comentários...