Ninjadoodle Posted February 2, 2018 Share Posted February 2, 2018 Hi @enpu / anyone else who might know how to do this How do I access the 'odd' and 'touched' variables I setup in the following class, from the sprites 'mousedown' function? game.createClass('S04Hitmap', { odd: false, touched: false, init: function(x, y) { this.sprite = new game.Sprite('s04Hitmap.png'); this.sprite.position.set(x, y); this.sprite.anchorCenter(); this.sprite.interactive = true; this.sprite.addTo(game.scene.mg); this.sprite.mousedown = function() { if (!this.touched && game.scene.ready) { game.Tween.add(game.scene.bunny1.sprite, { y: 232 }, 250, { delay: 0, easing: 'Back.In' }).start(); if (odd) { game.scene.passed(this.x, this.y); } else { game.scene.failed(this.x, this.y); } } } } }); Thank you in advance? Quote Link to comment Share on other sites More sharing options...
enpu Posted February 2, 2018 Share Posted February 2, 2018 You should bind the mousedown function so that then inside of it you can use this keyword to refer back to the class: game.createClass('S04Hitmap', { odd: false, touched: false, init: function(x, y) { this.sprite = new game.Sprite('s04Hitmap.png'); this.sprite.position.set(x, y); this.sprite.anchorCenter(); this.sprite.interactive = true; this.sprite.addTo(game.scene.mg); this.sprite.mousedown = this.mousedown.bind(this); }, mousedown: function() { if (!this.touched && game.scene.ready) { game.Tween.add(game.scene.bunny1.sprite, { y: 232 }, 250, { delay: 0, easing: 'Back.In' }).start(); if (this.odd) { game.scene.passed(this.sprite.x, this.sprite.y); } else { game.scene.failed(this.sprite.x, this.sprite.y); } } } }); Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted February 2, 2018 Author Share Posted February 2, 2018 Ahh, that makes sense - thank you!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.