arun Posted May 12, 2018 Share Posted May 12, 2018 hi, friends, I am a new in phaser framework. I am confusing about "this " keyword while using in Phaser States . please help me. Link to comment Share on other sites More sharing options...
zuklegugle Posted May 12, 2018 Share Posted May 12, 2018 As in any other case, this refers to the current object the code is running in, so using this inside phaser state just refers to this particular state object so to get a game object which that state belongs to you must use this.game to access it Link to comment Share on other sites More sharing options...
Mickety Posted May 12, 2018 Share Posted May 12, 2018 This is not strictly a Phaser thing. This gives context to whatever you assign it and depends on where you call it first. Read about it a bit more here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this You could use let for instance, but whatever variable you assign with let for instance in "create" cycle it will only be visible there and not in update or render cycle or wherever else. If you use this just by it self it will represent the object in context of which it has been called. It's hard to explain this in the first place so I'd suggest you read tutorials about it. Hope it helps. Link to comment Share on other sites More sharing options...
onlycape Posted May 12, 2018 Share Posted May 12, 2018 In this link they explain in detail the use of the "this" keyword in javascript: https://codeburst.io/javascript-the-keyword-this-for-beginners-fb5238d99f85 In my humble opinion (I'm a newbie in javascript and Phaser), your question is more related to javascript than to Phaser framework. Using more time in javascript learning at the end will save you a lot of time when developing in Phaser, and will provide you with other resources that in some cases the framework will not be able to offer. Regards. Link to comment Share on other sites More sharing options...
Recommended Posts