phaser-typescript-template icon indicating copy to clipboard operation
phaser-typescript-template copied to clipboard

Global variables

Open Davidgl1987 opened this issue 5 years ago • 1 comments

Hello! I love this template, thank you for it, but I have a question about global variables... How I can have a variable for all states, like config (music on/off, number of players...)? I'm a newbie in typescript, and I have tried to do it in many ways but always have an error on compilation time.

Thanks a lot again!

Davidgl1987 avatar May 26 '19 19:05 Davidgl1987

Did a couple quick searches and didn't find a good way to do it. I think it is discouraged in TypeScript. One way you could accomplish this is by bundling all those related properties into a class and then pass that between the states. This forum post shows how you can pass additional parameters when "starting" a state. You might need to work around issues with TypeScript complaining about the extra parameters though, I'm not sure.

mattherman avatar May 29 '19 19:05 mattherman