Daniel Belohlavek Posted January 17, 2015 Share Posted January 17, 2015 So I'm fairly new to Phaser and there are some topics I still haven't learn how to manage with TS. I saw some examples of the Isometric Plugin where Phaser plugins are loaded as follows:preload: function () { (...) // Add and enable the plug-in. game.plugins.add(new Phaser.Plugin.Isometric(game)); (...)}But reading the docs I realized that the class Phaser.Game does not contain a property "plugins". So I kept searching and I found the Phaser.PluginManager class that does have a "plugins" property but seems to take weird extra parameter. My question is: How can I create my own plugins and load them with typescript? I understand that my plugin class should extend Phaser.Plugin but I don't understand how to create an instance of the plugin in-game. Thanks for reading! Link to comment Share on other sites More sharing options...
jmp909 Posted September 23, 2015 Share Posted September 23, 2015 that code should work I think, but see my answer herehttp://www.html5gamedevs.com/topic/10016-how-does-one-use-plugins-in-typescript/?p=97735 i've had to create a .d.ts file for any plugin i use, mapping its functions. eg for the ScreenShake plugin (https://github.com/dmaslov/phaser-screen-shake) the following to be sufficient for getting it to compile ok in Visual Studio Code. (I'm new to this so I'm not claiming it to be perfect, but it works to get it up and running) declare module Phaser { module Plugin { export class ScreenShake extends Phaser.Plugin { constructor(game:Phaser.Game, parent:any); // not sure what "parent" type should be.. can anybody help here? setup(obj:Object):void; shake(count:number):void; } }} then in my code I callvar ss = <Phaser.Plugin.ScreenShake> this.game.plugins.add(Phaser.Plugin.ScreenShake);ss.shake(10);note the need for type casting from Phaser.Plugin to Phaser.Plugin.ScreenShake hope this helpsJ. Sanju 1 Link to comment Share on other sites More sharing options...
Sanju Posted December 30, 2015 Share Posted December 30, 2015 Thanks, jmp909! It works this way! Link to comment Share on other sites More sharing options...
Recommended Posts