striderxz Posted September 6, 2016 Share Posted September 6, 2016 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 More sharing options...
andrefbr21 Posted June 28, 2018 Share Posted June 28, 2018 bump I have the same problem too, i wanted to use slack-ui in my typescrupt project, but it's not wrking. The typescrupt definitions are not fouund, there are any workaround for this? Link to comment Share on other sites More sharing options...
andrefbr21 Posted June 28, 2018 Share Posted June 28, 2018 @striderxz got it to work, i just added what you did inside phaser.comments.d.ts pointed the right url path to kenney json. and added this line before any slick ui interface code. this.world.add(Preloader.slickUI.container.displayGroup); Link to comment Share on other sites More sharing options...
Recommended Posts