Le Twitch Posted July 29, 2014 Share Posted July 29, 2014 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 More sharing options...
lewster32 Posted July 29, 2014 Share Posted July 29, 2014 This by all rights should work as far as I can see... Can you post this as a jsfiddle or Codepen example? Link to comment Share on other sites More sharing options...
PXBILL Posted July 29, 2014 Share Posted July 29, 2014 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.testFunctionSo, "this" refer to "game" or "Main.game" ?? Link to comment Share on other sites More sharing options...
Dumtard Posted July 30, 2014 Share Posted July 30, 2014 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.testFunctionSo, "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 More sharing options...
Dumtard Posted July 30, 2014 Share Posted July 30, 2014 Created a fiddle, basically copied your code and put in some boilerplate to get it working(the prototype is exactly the same), everything seems fine? http://jsfiddle.net/cZDz4/ Link to comment Share on other sites More sharing options...
lewster32 Posted July 30, 2014 Share Posted July 30, 2014 Hmm, as I suspected Dumtard - It all looks fine code-wise. Twitch, do you have anything in your HTML that could be overlapping the game canvas? That's the only thing I can think of that would be causing this not to work. Link to comment Share on other sites More sharing options...
Le Twitch Posted July 30, 2014 Author Share Posted July 30, 2014 i found the problem! i had "this.input.maxPointers = 1;" in boot.js Link to comment Share on other sites More sharing options...
lewster32 Posted July 30, 2014 Share Posted July 30, 2014 That should still allow it to work I would've thought, since all that should stop working is multitouch? Link to comment Share on other sites More sharing options...
Le Twitch Posted July 30, 2014 Author Share Posted July 30, 2014 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 More sharing options...
lewster32 Posted July 30, 2014 Share Posted July 30, 2014 How bizarre. I reckon gremlins are at work here! Link to comment Share on other sites More sharing options...
Le Twitch Posted July 30, 2014 Author Share Posted July 30, 2014 How bizarre. I reckon gremlins are at work here! the invasion has only just begun Link to comment Share on other sites More sharing options...
Recommended Posts