1 decade ago
by igr
Hi,
the game I am working on finishes when the Hero is killed (naturally:).
I have the following code to go to the LevelgameOver:
if(!this.getHero()){ // Level restarts if Hero is killed
this.gameOver = true;
this.myDirector.jumpTo(LevelGameOver);
}
The problem is that at the game launch the game instead of starting at the LevelIntro, goes directly to the LevelGameOver, since this.getHero() returns NULL when I start the game.
Is there a smart workaround?
Thank you!
What about:
if ( this.getHero() ) {
if ( this.getHero.health <= 0 ) {
this.gameOver = true;
this.myDirector.jumpTo( LevelGameOver );
}
}
1 decade ago
by igr
Hi samgreen, thanks! But it never gets to the condition health<=0. The hero = null, is always the first. I had to eventually specify in the code that if on LevelIntro, then ignore the hero. Is not so elegant though:(
If you post some more code I might be able to help you out with it. You can use the method:
entity.kill()
to automatically set an entity's health to zero and remove it from the scene.
1 decade ago
by igr
Hi thanx, samgreen, the problem is that I cannot run a check on this.getHero().health in main.js, since at the game load, the hero entity is not created. So I have to check if getHero() is there at all first.
getHero() returns null if either the game loads or the hero gets killed.
Therefore if I say in the main.js:
if ( !this.getHero() ) {
this.gameOver = true;
this.myDirector.jumpTo( LevelGameOver );
}
Then the game goes directly to the gameOver after the load. I used a check on level and it works:
if(this.currentLevel == LevelMain){
if(!this.getHero()){ // Level restarts if Hero is killed
this.gameOver = true;
this.myDirector.jumpTo(LevelGameover);
}
}
But this is no good way to do it. Is there a better way?
Where are you putting the hero test?
If it's in your MyGame.init(), do the this.myDirector.loadLevel() before you test to see if your hero exists.
Page 1 of 1
« first
« previous
next ›
last »