複数のレベルを作成するのに少し問題があります。それらを正しい方法で作成しているかどうかはわかりませんが、プレーヤーとgoal_1、goal_2などがあります。基本的に、プレーヤーがtestObjectをgoal_1にヒットすると、level_2と呼ばれる新しい関数に移動し、そのhitTestの後にlevel_3に移動します。そのため、Level_1 は問題なく動作し、hitTest は機能し、level_2 を初期化しますが、プレーヤーと goal_2 または goal_1 をもう一度 hitTest しようとすると、それを通過して何もしません。
Enter_Frame リスナーの一部ではないため、level_2 は level_1 のようにすべてのフレームで呼び出されるわけではないことがわかりました。しかし、複数の Enter Frame イベントを作成し、それらを同時に実行しない方法がわかりません。それが複数のレベルを作成する正しい方法でさえある場合。
それを機能させるために何ができるかわかりますか?
private function gameLoop(e:Event):void
{
playerShoot();
playerControl();
playerStageBoundaries();
checkEndGameCondition();
checkPlayerOffScreen();
level_1();
}
private function level_1():void
{
if(player.hitTestObject(mGoal_1))
{
trace("Goal_1 Collision");
//Remove button for constant movement
btnShootPlayer = false;
mGoal_1.destroyGoal_1();
player.destroyPlayer();
//Update High Score text
nScore += 10;
updateHighScore();
stage.removeEventListener(Event.ENTER_FRAME, gameLoop);
//Update level
nLevel++;
updatePlayerLevel();
level_2();
}else
{
checkEndGameCondition();
}
}
public function level_2():void
{
stage.addEventListener(Event.ENTER_FRAME, gameLoop);
TweenMax.to(mGoal_1, 1, {y:40, repeat:-1, yoyo:true, ease:Power0.easeInOut});
trace("Level_2 Initiated");
//Keep Text Scores initiated
updateHighScore();
updatePlayerLives();
player = new mPlayer();
stage.addChild(player);
player.x = (stage.stageWidth / 2) - 280;
player.y = (stage.stageHeight / 2);
mGoal_1 = new goal_1();
stage.addChild(mGoal_1);
mGoal_1.x = (stage.stageWidth / 2) + 300;
mGoal_1.y = (stage.stageHeight) - 35;
if (player.hitTestObject(mGoal_1))
{
trace("Level 2 Hit test works!");
nScore += 10;
updateHighScore();
}
}