Copy link to clipboard
Copied
So the problem Im running into is that my "win" menu will not appear when I complete a certain objective. The objective is for my character from a platformer game to make it to a goal. The player "dude" can lose but cannot win. I thought this had to do with a error in the code cause the "goal" has a instance name called "Nanu" along with a hitbox. I tried typing differently with the hitTestObject with or without the hitbox. However none proved to work. There is only ONE goal and my teacher had said I was treating him like he was a array like the enemies when he wasnt. I think thats where my errors started to appear. The teacher is usually too busy with help with this error and I feel Ill be finished if I end up fixing it. The thing that happens is that the character will jump pass the goal like they are non existent so Im unable to win the game. Anyways Ill be giving the coding format of the game win menu. I will be adding the "lose menu" as well to compare it with cause unlike the win menu the lose menu actually works and appears. If I need to show off the whole code or show the file in some way let me know^^"
Win Menu:
function Nanuhitsdude(e: Event): void {
/*for (var i = 0; i < Nanu.length; i++) {*/
if (dude.hitbox.hitTestObject(Nanu.hitbox)) {
//keepingTrackOfLives();
dude.gotoAndStop(4);
if (dude.x > 225) {
dude.x -= 100
AniriPain.play();
} else {
dude.x += 100
AniriPain.play();
}
}
WinGame();
}
function WinGame() {
//IWasHit++
//trace(IWasHit);
//Heart.gotoAndStop(IWasHit);
if (dude.currentFrame == 4) {
stage.removeEventListener(KeyboardEvent.KEY_UP, keyUP);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDOWN);
stage.removeEventListener(Event.ENTER_FRAME, eFrame);
addChild(winMenu);
winMenu.x = 0;
winMenu.y = 5;
winMenu.playAgain.addEventListener(MouseEvent.CLICK, playGameAgainWon);
//for (var ii = 0; ii < enemiesArray.length; ii++) {
//enemiesArray[ii].removeEventListener(Event.ENTER_FRAME, moveenemies);
trace(Nanu.hasEventListener(Event.ENTER_FRAME));
}
stage.removeEventListener(Event.ENTER_FRAME, Nanuhitsdude);
trace(stage.hasEventListener(Event.ENTER_FRAME));
}
function playGameAgainWon(e: MouseEvent): void {
removeChild(winMenu);
/*for (var ii = 0; ii < enemiesArray.length; ii++) {
enemiesArray[ii].visible = false;
enemiesArray[ii].y = -50;
}*/
//m = -1
Nanu = [];
//stage.focus = null;
//stage.addEventListener(KeyboardEvent.KEY_UP, keyUP);
//stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDOWN);
//stage.addEventListener(Event.ENTER_FRAME, eFrame);
//this.removeEventListener(Event.ENTER_FRAME, eFrame);
dude.x = 275;
//IWasHit = 1;
//score.text = String(deletedenemiesArray.length);
//score.text = String(0);
gotoAndPlay(1);
}
Lose Menu:
function enemyhitsdude(e: Event): void {
for (var i = 0; i < enemiesArray.length; i++) {
if (dude.hitbox.hitTestObject(enemiesArray.hitbox)) {
//keepingTrackOfLives();
dude.gotoAndStop(4);
if (dude.x > 225) {
dude.x -= 100
AniriPain.play();
//AniriRun.stop();
} else {
dude.x += 100
AniriPain.play();
//AniriRun.stop();
}
}
}
LostGame();
}
//Losing Menu
function LostGame() {
//IWasHit++
//trace(IWasHit);
//Heart.gotoAndStop(IWasHit);
if (dude.currentFrame == 4) {
stage.removeEventListener(KeyboardEvent.KEY_UP, keyUP);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDOWN);
stage.removeEventListener(Event.ENTER_FRAME, eFrame);
addChild(loseMenu);
//AniriRun.stop();
songChannel.stop();
AniriLost.play();
loseMenu.x = 0;
loseMenu.y = 5;
loseMenu.playAgain.addEventListener(MouseEvent.CLICK, playGameAgainLost);
for (var ii = 0; ii < enemiesArray.length; ii++) {
//enemiesArray[ii].removeEventListener(Event.ENTER_FRAME, moveenemies);
trace(enemiesArray[ii].hasEventListener(Event.ENTER_FRAME));
}
stage.removeEventListener(Event.ENTER_FRAME, enemyhitsdude);
trace(stage.hasEventListener(Event.ENTER_FRAME));
}
}
function playGameAgainLost(e: MouseEvent): void {
removeChild(loseMenu);
//AniriRun.stop();
//AniriRun.play();
/*for (var ii = 0; ii < enemiesArray.length; ii++) {
enemiesArray[ii].visible = false;
enemiesArray[ii].y = -50;
}*/
//m = -1
enemiesArray = [];
stage.focus = null;
//stage.addEventListener(KeyboardEvent.KEY_UP, keyUP);
//stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDOWN);
//stage.addEventListener(Event.ENTER_FRAME, eFrame);
//this.removeEventListener(Event.ENTER_FRAME, eFrame);
dude.x = 275;
//IWasHit = 1;
//score.text = String(deletedenemiesArray.length);
//score.text = String(0);
gotoAndPlay(1);
}
Copy link to clipboard
Copied
what's the error message and what line of code is triggering the error?
Copy link to clipboard
Copied
The thing is I usually don't see a error message the player will just walk pass the goal like it doesn't exist.
The errors I did get before was null object but I was able to fix that by adding a null. I'd get errors of numbers such as 1008?
Copy link to clipboard
Copied
the first error i see is nothing calls Nanuhitsdude function
the second error is Nanu looks like it's an array
the third error is you can't apply a hittestObject to an array.
there are probably more errors.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now