Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Store class in Phaser.Group, needs Typscript definitions for PIXI classes?


Tarion
 Share

Recommended Posts

Hi, I'm looking for definitions of the PIXI classes used inside Phaser.

 

Especially the PIXI.DisplayObject which I like to extend to be able to store my custom classes inside a groups.

 

Maybe it's the wrong approach, what I'm trying is the following:

npcs:Phaser.Group;// ...var npc = new Npc(this.world.randomX, this.world.randomY, this);this.npcs.add(npc);

Using:

export class Npc extends Mobile {// ...
    export interface IMobile {        Sprite:Phaser.Sprite;        update();    }    export class Mobile implements IMobile {        Sprite:Phaser.Sprite;        update() {        }    }

But it fails with:

 

 

Uncaught TypeError: Cannot set property '_iPrev' of undefined phaser.js:1559:27
PIXI.DisplayObjectContainer.addChild phaser.js:1559:27

 

 

 

 

Link to comment
Share on other sites

Your approach is fine but your interface doesn't look quite right. Group.add expects you to give it a valid display object, but Mobile doesn't extend a display object, it just seems to have one as a property.

 

There's no TypeScript definitions file for Pixi yet I don't believe, but the second they finish making one we'll merge it with our defs file too!

Link to comment
Share on other sites

I've seen scripts that try to generate defs automatically from JS source. But I've never seen one that worked that well :) The Phaser defs file used one and we had to manually fix it by hand. Took forever. Probably could have written my own in the time it took us to manually edit!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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