Jump to content

adding extended sprite to scene


Mercutio
 Share

Recommended Posts

Hi,

For the record I am just a hobbyist so I don't know many of the ins and outs of programming.

 

I am trying to isolate? modulize? (not sure which is right word) my player to a class so I did below:


class Player extends Phaser.Physics.Arcade.Sprite{
    constructor(scene, x, y, texture){
        super(scene, x, y, texture);

        .....etc....//my own stuff

    }

}

but i cant get it to render on screen or to update

the way i have been doing it before is

player = this.physics.add.sprite(x,y,texture);

I assume to use my class it would be

player = new Player(this, 0, 0, 'someloadedimageinpreload');

 

Based on some readings i think I may have to add it to displayList and updateList?

But I don't get how to do that...

 

Can someone help me please?

 

 

Link to comment
Share on other sites

  • 2 months later...

Thanks for the help on this one. This stumped me as well as I'd like to split up my code in several files and extending sprites seems to be a good way to make it more modular.

Why havent they added a generic .add( x ) function to game that just looks at the type and knows that its a sprite? the this.add.existing( x ) looks rather cryptic?

Link to comment
Share on other sites

  • 4 months later...

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...