Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gnesher opened this issue Jan 29, 2019 · 4 comments
Closed

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

gnesher opened this issue Jan 29, 2019 · 4 comments

Comments

@gnesher
Copy link

gnesher commented Jan 29, 2019

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

@digitsensitive
Copy link
Owner

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.

@gnesher
Copy link
Author

gnesher commented Jan 30, 2019

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

@digitsensitive
Copy link
Owner

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?

@digitsensitive
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants