Mercutio Posted July 11, 2018 Share Posted July 11, 2018 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 More sharing options...
samme Posted July 11, 2018 Share Posted July 11, 2018 https://github.com/samme/phaser3-faq/wiki#how-do-i-extend-a-game-object Link to comment Share on other sites More sharing options...
mezerotm Posted July 11, 2018 Share Posted July 11, 2018 I think your trying to do this > https://github.com/nkholski/phaser3-es6-webpack/blob/master/src/sprites/Mario.js Link to comment Share on other sites More sharing options...
samme Posted July 11, 2018 Share Posted July 11, 2018 player = new Player(this, 0, 0, 'image'); this.add.existing(player); rodrigezer 1 Link to comment Share on other sites More sharing options...
Mercutio Posted July 12, 2018 Author Share Posted July 12, 2018 Thanks, sorry I should have replied sooner but yes I figured it out after the first link. Link to comment Share on other sites More sharing options...
johncl Posted September 29, 2018 Share Posted September 29, 2018 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 More sharing options...
rodrigezer Posted February 22, 2019 Share Posted February 22, 2019 On 7/11/2018 at 12:41 AM, samme said: player = new Player(this, 0, 0, 'image'); this.add.existing(player); awesome dude !! i was googlin it for a while. Link to comment Share on other sites More sharing options...
Recommended Posts