我在这里遇到问题,因为我试图在屏幕上显示祝贺消息时删除矩形的任何实例。代码有点乱,但我一直在弄乱它来试图解决这个问题。如果我将其更改addChild
为stage.addChild
这会给我由于在shootMob
函数中拍摄和删除它们而导致的错误。我也将其称为,rectangle.parent.removeChild(rectange)
但这也行不通。有任何想法吗?
function spawnMob1():void
{
if (gameLevel==1)
{
var rectangle:MovieClip = new ball_mc();
rectangle.x = randomRange(583);
rectangle.y = randomRange(100);
addChild(rectangle);
var mobMoveX:Tween = new Tween(rectangle, "x", None.easeOut, rectangle.x, character_mc.x, 6, true);
var mobMoveY:Tween = new Tween(rectangle, "y", None.easeOut, rectangle.y, character_mc.y, 6, true);
rectangle.visible = true;
rectangle.addEventListener(MouseEvent.CLICK, shootMob);
function shootMob(e:MouseEvent): void
{
if (contains(rectangle))
{
removeChild(rectangle);
score_txt.text = String(score);
}
score+=20;
trace("Score:" + score);
}
if (score>=60)
{
trace("Congratulations!");
congratulations1_mc.visible = true;
trace("GameLevel:" + gameLevel);
removeChild(rectangle);
// rectangle.visible = false;
gameLevel = 0;
}
character_mc.addEventListener(Event.ENTER_FRAME, charHit);
function charHit(event:Event): void
{
if (rectangle.hitTestObject(character_mc))
{
if (contains(rectangle))
{
removeChild(rectangle);
if (health>0)
{
health-=5;
health_txt.text = String(health);
trace("boop");
trace("Health:" + health);
} else if (health<=0) {
trace("You have died");
death_mc.visible = true;
gameLevel=0;
}
}
}
}