Jump to content

Referencing JS Phaser plugins from Typescript


striderxz
 Share

Recommended Posts

Hi everyone,

I've been trying to find a way to reference phaser plugins written in javascript, which have no definition files, from typescript. At the moment I'm trying to reference slick-ui, so I'll use it as an example.

So far the method that has gotten me closer to using it has been defining a dummy definition as follows:

typings/slick-ui.d.ts

/// <reference path="phaser.comments.d.ts" /> 
declare module Phaser {        
    module Plugin {		        
        var SlickUI : any;
    }
}

declare module SlickUI{
    var Element : any;
}

 

example.ts

 /// <reference path="typings/phaser.comments.d.ts"/>
/// <reference path="typings/slick-ui.d.ts"/>
class Example extends Phaser.Game
{
  //...
  
  preload() {
     //...

     this.slickUI = this.game.plugins.add(new Phaser.Plugin.SlickUI(this.game, this.stage));
     
     //Also tried the following beforehand, though Im not sure it would work the same for TS 
     //this.slickUI = this.game.plugins.add(Phaser.Plugin.SlickUI);
     
     this.slickUI.load('resources/ui/kenney/kenney.json');
  }


  create() {

     //...
     var panel = new SlickUI.Element.Panel(8, 8, 150, game.height - 16);  
  }

  //...
}

 

Using the dev tools debugger I found out it actually loaded the plugin correctly and set its properties (e.g. the game property of the plugin) before it tries to load the theme from the json file. However, the program fails when this method is executed, stating that the property "game" is undefined. 

Has anyone found a way to load js plugins from typescript or why the slickUI object would lose the game reference?

Thank you!!

Link to comment
Share on other sites

  • 1 year later...
 Share

  • Recently Browsing   0 members

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