Jump to content

A question about classes (trying to get more efficient)


Ninjadoodle
 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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