ZeroGravity Posted October 21, 2015 Share Posted October 21, 2015 Hi, I am bit puzzled why all these work (okay I understand why global game works, its Phaser.Game object and can see the functions). So technically there is no problem here, except that I dont understand why these this and this.game work too. After all, where I create preload object the game is not assigned to anywhere. var game = new Phaser.Game(x, y, Phaser.CANVAS, 'game');var BasicGame = {}; BasicGame.preload = function(game) {}; BasicGame.preload.prototype = { preload : function() { var logo = this.add.sprite(game.world.centerX, game.world.centerY, 'background'); logo.anchor.setTo(0.5, 0.5); ......but logo could be also defined: var logo = game.add.sprite(...) <-- I understand this .. as far as i understand, its that global game... or ...var logo = this.game.add.sprite(...)And I see that BasicGame.preload is defined as function(game) which has no game object inside it and has no method add inside it (not even in prototype). And that makes me puzzle, why, how, what? What I am missing here? Which one would be most correct? /ZeroGravity Link to comment Share on other sites More sharing options...
rich Posted October 21, 2015 Share Posted October 21, 2015 Interphase 1 - State Manager Guide - covers this in great depth. In short though, the State Manager adds the properties in for you (add, load, etc) Link to comment Share on other sites More sharing options...
ZeroGravity Posted October 21, 2015 Author Share Posted October 21, 2015 Thanks for the reply. I did some debuggin. It seems that when entering to preload-method, "this" points to Basicgame.preload and that does contain the add method and game object, which contains again add method, which I assume are the same method (both). Apparently state manager injects the methods and objects as you said ... So, most likely the correct answer to my question (Which one would be most correct?) is: they all are equal, yet probably this.add could be most "reusable" (if ever needed, maybe one day you drop game object from this or my code does not have global game)? That book looks very intriguing. Better get it. [edit] Stupid me ... its me who injects the game to the Basicgame.preload ... I better get my coat. [edit] /ZG Link to comment Share on other sites More sharing options...
Recommended Posts