Ninjadoodle Posted June 18, 2018 Share Posted June 18, 2018 Hi @enpu / panda people I've been setting up my classes this way ... game.createClass('S04Clue', { init: function(x, y) { this.sprite = new game.Sprite('s04Clue.png'); this.sprite.position.set(x, y); this.anchorCenter(); this.addTo(game.scene.bg); } }); ... but, I have recently learned that you can also setup classes this way (I assume, this method is setting up a class by 'extending' the sprite class) ... game.createClass('S04Clue', 'Sprite', { texture: 's04Clue.png', init: function(x, y) { this.position.set(x, y); this.anchorCenter(); this.addTo(game.scene.bg); } }); I notice that in the second version, if I want to use a mouse event inside the class, then I don't have to bind like this - this.sprite.mousedown = this.mousedown.bind(this); Are there any reasons for using one method over another or any pitfalls I can expect with either? Thanks heaps for any tips Quote Link to comment Share on other sites More sharing options...
enpu Posted June 18, 2018 Share Posted June 18, 2018 Both works, but i would say that it really depends on how complex your class is going to be. If it's just really simple class then i would extend it from Sprite, otherwise i would make empty class and have the Sprite on it's own property. Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted June 18, 2018 Author Share Posted June 18, 2018 Hi @enpu Thanks heaps - thanks for the tip! I thought that might be the case Quote Link to comment Share on other sites More sharing options...
8bitdna Posted June 18, 2018 Share Posted June 18, 2018 Good question @Ninjadoodle, I was wondering this yesterday! 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.