1 decade ago by Apiheld
I do have Constants in my game. Where do I put them such that I have access to them while the game loads up? They are limited to the game's scope.
Example: As a warmup exercise, I implement Tetris. I'm not sure if I go with 16x16 or 32x32 tiles. Anyways, it's always good to have as few fixed numbers in your code as possible. To be able to scale everything up later, I need a Constant called TILESIZE. However, the size of a block depends on the TILESIZE, like so:
size: { x: ig.game.TILESIZE, y: ig.game.TILESIZE},
So, the TILESIZE needs to be known by EntityBlock as soon as possible.
I read in some thread that you can put global variables in the game scope. However, if I run my game, it complains "Cannot read property 'TILESIZE' of null", meaning, that ig.game is not known to EntityBlock at first.
Two questions:
1. Where to put Constants generally speaking?
2. Is there a better way to give the game a specific TILESIZE except for putting it into a Constant?
Example: As a warmup exercise, I implement Tetris. I'm not sure if I go with 16x16 or 32x32 tiles. Anyways, it's always good to have as few fixed numbers in your code as possible. To be able to scale everything up later, I need a Constant called TILESIZE. However, the size of a block depends on the TILESIZE, like so:
size: { x: ig.game.TILESIZE, y: ig.game.TILESIZE},
So, the TILESIZE needs to be known by EntityBlock as soon as possible.
I read in some thread that you can put global variables in the game scope. However, if I run my game, it complains "Cannot read property 'TILESIZE' of null", meaning, that ig.game is not known to EntityBlock at first.
Two questions:
1. Where to put Constants generally speaking?
2. Is there a better way to give the game a specific TILESIZE except for putting it into a Constant?