englercj / phaser-tiled

A tilemap implementation for phaser focusing on large complex maps built with the Tiled Editor.
MIT License
290 stars 31 forks source link

Typescript issues and setting up the plugin #35

Closed wgronewold closed 8 years ago

wgronewold commented 8 years ago

Hey all,

I'm having a few issues with phaser-tiled and typescript.

First the typescript definitions conflict with p2.d.ts, pixi.d.ts, and with phaser.d.ts.

My next issue is adding the plugin to the game and getting it to mesh with the loader.

this.add.plugin(Phaser.Plugin.Tiled); I get typeof Tiled is not assignable to parameter of type 'Plugin'. Property 'active' is missing in type 'typeof Tiled'

Digging around in englercj's phaser fort of "Link to the Past", I found this way:

this.add.plugin(new Phaser.Plugin.Tiled(this));

When I do this is needs a reference to the game and to a display object. this.add.plugin(new Phaser.Plugin.Tiled(this.game, this.stage));

This makes VS Code happy, but it leads to the next issue. this.load.tiledmap(cachKey('map', 'tiledmap'), 'assets/map.json', null, Phaser.Tilemap.Tiled_JSON);

Gives an error saying that tiledmap DNE on type 'Loader' and I also get a supplied parameters error for cacheKey saying that parameters do not match any signature of call target.

Here is a link to my source code. I add the plugin in the Boot.ts file, and try to load everything in the Preload.ts File

https://bitbucket.org/wgronewold/tilemapzoom_scalegroup/src

I'm currently using node.js to serve app to localhost and the typescript compiles to the game.js file in the bin directory.

Any help is appreciated. Thanks

englercj commented 8 years ago

What version of Phaser are you using? This repo is only compat with Phaser 2.3

wgronewold commented 8 years ago

Should be Phaser 2.3. "Tarabon.

Edit: Double checked to make sure I did revert to 2.3 and it is.

wgronewold commented 8 years ago

Opps I had to change the reference path in the phaser-tiled.d.ts. That was causing the conflicting files. Still having the same issues getting the plugin to run.

englercj commented 8 years ago

The second parameter to the plugin is not the stage, not sure why you are passing that in.

Still having the same issues getting the plugin to run.

What issue? Your issue was "I get a typescript error". What runtime error do you get with this.add.plugin(Phaser.Plugin.Tiled);?

Gives an error saying that tiledmap DNE on type 'Loader' and I also get a supplied parameters error for cacheKey saying that parameters do not match any signature of call target.

Could be because you are passing the stage into the plugin creation for some reason. You don't need to, Phaser will set the parent property in the add method:

https://github.com/photonstorm/phaser/blob/v2.3.0/src/core/PluginManager.js#L65-L66

Also, sounds like another TS error, not a runtime one. Are you sure this is a runtime error?

wgronewold commented 8 years ago

Apologies I'm a bit scatterbrained playing around with the code.

Originally it was a runtime error. this.add.plugin(Phaser.Plugin.Tiled)

Argument of type 'typeof Tiled' is not assignable to parameter of type 'Plugin'. Property 'active' is missing in type 'typeof Tiled'. class Phaser.Plugin namespace Phaser.Plugin

After building I get Argument of type 'typeof Tiled' is not assignable to parameter of type 'Plugin'. class Phaser namespace Phaser

So I believe it has something to do with how typescript modules work. Phaser.Plugin.Tiled should be pointed to the namespace Phaser.Plugin right?

wgronewold commented 8 years ago

You can close this! VS Code is having a fit because it doesn't like something. I'm a newb. I put too much trust into VS Code, and I think it is right every time it has an error.

I'm ignoring the errors and my tilemap is rendering with no problems.

Thanks for your patience.

englercj commented 8 years ago

Argument of type 'typeof Tiled' is not assignable to parameter of type 'Plugin'. Property 'active' is missing

That is a TS error, not a runtime error. Sounds like there are just definition file issues going on. If you sort that out I'm pretty sure it will be fine.