Jump to content

function not working


Le Twitch
 Share

Recommended Posts

Main.Game = function (game) {  };var squareA;        Main.Game.prototype = {        create: function() {        squareA = this.add.sprite(55, 370, 'colourSquare', 'red');                squareA.inputEnabled = true;                squareA.events.onInputDown.add(this.testFunction, this);    },        testFunction: function() {                console.log('it works');            }};

nothing happens when i click on the 'squareA' sprite. can't figure out why it doesn't work

Link to comment
Share on other sites

I just had a fast look, but i think must be related with the "scopes", you are calling:

this.add.sprite(55, 370, 'colourSquare', 'red');

and then "this":

this.testFunction

So, "this" refer to "game" or "Main.game" ??

Link to comment
Share on other sites

I just had a fast look, but i think must be related with the "scopes", you are calling:

this.add.sprite(55, 370, 'colourSquare', 'red');

and then "this":

this.testFunction

So, "this" refer to "game" or "Main.game" ??

 

If it's a state which it looks like it is Main.Game will have access to both. States have access to a number of helper objects http://docs.phaser.io/Phaser.State.html

Link to comment
Share on other sites

That should still allow it to work I would've thought, since all that should stop working is multitouch?

 

i rewrote all my code for "Main.Game" and made sure everything worked properly every time i added a new line of code in, then i added "this.input.maxPointers = 1;" back into boot.js and everything is normal and it works. i cross referenced my new and old code and they we're both the same. so weird...

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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