rblopes / generator-phaser-plus

[🛑 DISCONTINUED] It has been a long journey but development of `generator-phaser-plus` is now over. I recommend you have a look and fork `yandeu/phaser-project-template` instead.
https://github.com/yandeu/phaser-project-template
MIT License
144 stars 14 forks source link

Class inheritance from plugins #13

Closed Laokoont closed 8 years ago

Laokoont commented 8 years ago

I'm using an external plugin called phaser-plugin-isometric to create isometric game spaces. I add this plugin to Phaser via simple command within the preload() method of my Boot state:

preload () {
    // Load the graphical assets required to show the splash screen later.
    this.load.pack('boot', null, assets);
    this.game.plugins.add(new Phaser.Plugin.Isometric(this.game));

It seems to work fine in all forthcoming states as well.

It, among other things, extends Phaser object with isoSprite function that creates isometric sprites. It works like charm when I use it explicitly in my Game state:

 tile = this.game.add.isoSprite(xx, yy, 0, 'tile', 0, this.isoGroup);

I would like to be able to describe object classes that inherit from isoSprite the same way they can inherit basic Sprite class from Phaser with something like this:

/* Tile object class, creates isometric tiles
*/
export default class Tile extends Phaser.isoSprite {

However I have found out that in this case the isoSprite method appears undefined. How can I make it visible in the scope of my object class?

rblopes commented 8 years ago

Hi, @Laokoont. Thanks for trying my Yeoman generator.

I didn't knew much about the Isometric plugin, haven't tried it yet, but I made a little test to see how things are, and looked in the source codes for some clues.

The correct class to extend is Phaser.Plugin.Isometric.IsoSprite.

export default class Tile extends Phaser.Plugin.Isometric.IsoSprite {
    constructor (game, x, y, z, key, frame) {
        super(game, x, y, z, key, frame);
        // ... etc ...
    }
}

isoSprite is just a function added by the plugin so you can create isometric sprites the same way you could create regular sprites using the game.add.* API calls.