Zampano Posted May 26, 2017 Share Posted May 26, 2017 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 More sharing options...
samme Posted May 26, 2017 Share Posted May 26, 2017 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; } }; Zampano 1 Link to comment Share on other sites More sharing options...
Zampano Posted May 26, 2017 Author Share Posted May 26, 2017 Oh wow. I was pretty sure I tried that Oo Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts