phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.12k stars 7.1k forks source link

Consistent API around referencing the game instance #25

Closed jessefreeman closed 11 years ago

jessefreeman commented 11 years ago

There are 2 inconsistent ways to get reference to the game instance depending on what class you are in. Game Objects have a private variable _game while states have game. This should be the same throughout the Framework. I suggest using a game getter/setter to clean things up in the Basic class

Plus this is a TS issue since technically you shouldn't be able to access private vars when extending a class so it would be best to shy developers away from directly accessing anything with an underscore.

photonstorm commented 11 years ago

States are allowed to have a public game property because they are never used WITHIN the Game framework, i.e. they are not objects that belong to Phaser. They are a list of short-cuts and proxy methods to make coding (on the game side) less verbose, I guess think of them as being stripped down versions of Phaser.Game.

State could technically use a getter to _game instead, but it doesn't help consistency because it's still exposed as a public game property.

Every other class uses a private _game.