digitsensitive / phaser3-typescript

Phaser 3 and TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(phaser.d.ts) Config.width/height can be string?

gnesher opened this issue · comments

Why are we accepting strings as valid values for the game height / width? It just means I have to cast them to whenever I want to perform arithmetic operations (otherwise I get the following error: [ts] The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. [2362])

Happy to open a pull request, just didn't know if it's there for a reason

commented

Hello @gnesher! Strings are accepted as valid for game height and width because you might want to use percentages (f.e. 60% width and 100% height). Even though I haven't used this yet, I would leave it. Is that what you meant?

Have a look at the official phaser code.

Oh interesting. I've been following a simple tutorial (https://gamedevacademy.org/phaser-3-tutorial/) which tells you to put a sprite in the middle of the screen using this.sys.game.config.height / 2 which is now invalid. Not sure how to work around that except to manually cast these to number when I know the value

commented

That is true, this will be invalid. The best thing would be probably, that if you choose to use a string f.e. 20%, that the phaser framework would calculate the absolute size and save that as the width so you can access it with this.sys.game.config.height. Maybe something to discuss in the official phaser respository?

commented

@gnesher Are you going to open a discussion in the official phaser repository or will you leave it as it is?