Annoraaq / grid-engine

A grid based movement engine compatible with Phaser3.
https://annoraaq.github.io/grid-engine/
Apache License 2.0
241 stars 20 forks source link

Phaser is not defined when initializes GridEngine in a ts file for scene #495

Closed r000tmnt closed 3 months ago

r000tmnt commented 3 months ago

Hello. I'm learning to use Phaser with Quasar framework. The demo I want to build is a 2D roguelike scene which is suitable with grid based movement.

I follow the example in the document to set up the plugin. It seems when the triggered the create stage of the scene. The gridEngine is register but the create function does not work properly and stop the rest of the code.

I've prepared a reproduce of the bug in codeSandbox

After open up the page and run the project. Please inspect the page to see the console log. There should be a message similar to this image. 圖片 Please help.

Annoraaq commented 3 months ago

Hey @r000tmnt, it seems that I don't have access to the codeSandbox. Is it maybe set to private?

r000tmnt commented 3 months ago

Hello @Annoraaq, I've make sure the link is working this time. Thanks for the response and plase take a look.

Annoraaq commented 3 months ago

GridEngine needs a global variable called Phaser. I am not sure why this is not set (and maybe it is also not optimal that GridEngine relies on this). However, as a workaround can you try to manually create that global variable in your scene?

Maybe import * as Phaser from 'phaser'; is already sufficient.

r000tmnt commented 3 months ago

Unfortunately import * as Phaser from 'phaser'; is not working as we thought.

Annoraaq commented 3 months ago

Did you try to set the global variable? window.Phaser = Phaser; for instance.

r000tmnt commented 3 months ago

My bad. I haven't thought about setting global variable with window. It worked. Thanks for the help.

Annoraaq commented 3 months ago

You're welcome. I think we should add a cleaner solution to GridEngine that removes the need for this workaround.