Jump to content

wich word "this" replace in this line ?


Recommended Posts


in this snippet wich object "this" replace at this line, if i would write this  :D without "this" what must i write  :

        playerPapers5 = this.game.add.group()

the  part of the snippet :

var theGame = function(game){

	playerPapers5 = null

theGame.prototype = {
	create: function(){


		playerPapers5 = this.game.add.group()



Link to comment
Share on other sites

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),


Link to comment
Share on other sites

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


  • Recently Browsing   0 members

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