Jump to content

Function access


Zampano
 Share

Recommended Posts

Hello again, so I've got this state:

BasicGame.Game = function (game) {
	//...
}

BasicGame.Game.prototype = {
		
    create: function () {
		//...
		this.game.onBlur.add(pauseGame, this);
		
		function pauseGame(game) {
			sfx_music.pause();
			this.game.paused = true;
		};
    },

    update: function () {
		if (escKey.isDown)
		{			
			this.pauseGame();
		}
	}
};

So the problem is that when calling this.pauseGame(); in the update function throws the error: Uncaught TypeError: this.pauseGame is not a function

I'm aware that the I'm either not calling it right (I tried everything I could think of though) or it simpy is not available in this context at all.
When I declare the function outside of the create function, I get an when trying to add it to onBlur, so it is not that easy as well.

What do I do to make it available in both contexts?

Link to comment
Share on other sites

This should work:

BasicGame.Game.prototype = {

  create: function () {
		// ...
    this.game.onBlur.add(this.pauseGame, this);
  },

  update: function () {
    if (escKey.isDown) {
      this.pauseGame();
    }
  },

  pauseGame: function () {
    // ...
    this.game.paused = true;
  }

};

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...