espace Posted October 5, 2016 Share Posted October 5, 2016 hi, in this snippet wich object "this" replace at this line, if i would write this without "this" what must i write : playerPapers5 = this.game.add.group() the part of the snippet : var theGame = function(game){ ////////////////////////////////////////////////////////////////////////////////////////// //GROUP playerPapers5 = null } theGame.prototype = { create: function(){ this.game.physics.startSystem(Phaser.Physics.ARCADE) playerPapers5 = this.game.add.group() } Link to comment Share on other sites More sharing options...
douglas Posted October 5, 2016 Share Posted October 5, 2016 according to this code it means the game menuState = { create: function() { game.world.setBounds(0, 0, 640, 360); var b = (game.add.image(0, 0, "menubg"), game.add.image(230, 200, "whiteplanemenu")); b.anchor.set(.5, .5); this.playbutton = game.add.button(428, 183, "playgamebutton", this.start), this.instructionbutton = game.add.button(428, 237, "instructionbutton", this.instruction), this.aboutbutton = game.add.button(573, 237, "aboutbutton", this.about), } game = new Phaser.Game(640, 360); game.global = { score: 0, bgm: new Object, gameoverbgm: new Object, ingamebgm: new Object, background: game.rnd.between(0, 4) }, game.state.add("boot", bootState), game.state.add("load", loadState), game.state.add("menu", menuState), game.state.start("boot"); Link to comment Share on other sites More sharing options...
espace Posted October 5, 2016 Author Share Posted October 5, 2016 hi douglas, when i replace "this" by "game" i have an error. Link to comment Share on other sites More sharing options...
o0Corps0o Posted October 5, 2016 Share Posted October 5, 2016 I would replace this.game.add.group() with this.add.group(); but thats just how my games are set up... Link to comment Share on other sites More sharing options...
espace Posted October 5, 2016 Author Share Posted October 5, 2016 ok thanks when i do playerPapers5 = game.add.group() or playerPapers5 = this.add.group()that works. thanks both douglas 1 Link to comment Share on other sites More sharing options...
douglas Posted October 5, 2016 Share Posted October 5, 2016 i think that's what it means this reference the game i don't know if this fun fun function episode explain it better then that example with global objects that i understand just the half Link to comment Share on other sites More sharing options...
tips4design Posted October 5, 2016 Share Posted October 5, 2016 this is usually the instance of the game state you are in, not the instance of the game. Link to comment Share on other sites More sharing options...
douglas Posted October 5, 2016 Share Posted October 5, 2016 @tips thx for engaging an interesting way of viewing phaser gamedev it should work in a term of process Link to comment Share on other sites More sharing options...
in mono Posted October 6, 2016 Share Posted October 6, 2016 The "this" in the first example refers to the current Phaser.State. The fact that you can call this.game.add the same way that you can call this.add is dictated by the fact that they both refer to the same thing (i.e. the state has a reference to an instance of Phaser.GameObjectFactory; the game has a reference to that very instance - and it's the same for a lot of other things). Link to comment Share on other sites More sharing options...
Recommended Posts