Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by rootbeerking

Hello, this will probably be a very easy question to solve, so forgive me for asking. I'm working on getting my player to respawn after dying. Currently I'm doing this by using
ig.game.loadLevelDeferred( LevelTest );

This works fine, but the issue is that this would only work for one particular level. I was wondering how I would make it so that depending on what level the player died in would be the level that is reset.

I take it I would somehow have to assign a variable whenever a level is loaded and then use something like:
ig.game.loadLevelDeferred( this.currentLevel );

But I'm not sure how to do that exactly. Any help would be much appreciated, as always.

Thank you very much for taking the time to help me.

1 decade ago by paularmstrong

in your main game, override loadLevel and have it set currentLevel before passing on to the parent method:

Main = ig.Game.extend({
    
    // ...

    loadLevel: function (level) {
        this.currentLevel = level;
        this.parent(level);
    },

    // ...
});

The trick to understand is that loadLevelDeferred just waits until the current iteration through all entity update and draw functions for the current frame have completed, then calls ig.game.loadLevel();

Having that above, you should now be able to call
this.loadLevelDeferred(this.currentLevel); 
// or this is the same, if you're not calling from your game class:
ig.game.loadLevelDeferred(this.currentLevel);

1 decade ago by rootbeerking

Hmm not sure why, but that didn't work... Here's what I've done:

main.js:
init: function() {
//etc

this.loadLevel( LevelTest );
},
		
loadLevel: function( level ) {
    this.currentLevel = level;
    this.parent( level );
//etc

player.js:
  check: function( other ) {
  //etc
	    else {
		ig.game.loadLevelDeferred(this.currentLevel);
	  }
	  
	  
    },

1 decade ago by paularmstrong

Scoping issue...

In player.js, EntityPlayer doesn't have an instance for "this.currentLevel". that should be:

ig.game.loadLevelDeferred(ig.game.currentLevel);

1 decade ago by rootbeerking

I thought that was the issue, just didn't know I could use ig.game. to fix it. Thanks for the help!
Page 1 of 1
« first « previous next › last »