bp74 / StageXL

A fast and universal 2D rendering engine for HTML5 and Dart.
http://www.stagexl.org
Other
880 stars 82 forks source link

Syntax of StageOptions is confusing #294

Closed dashtodartlang closed 6 years ago

dashtodartlang commented 6 years ago

Hi. I am completely new to StageXL and animations, so sorry in advance if this is silly. I am confused about the syntax of StageOptions. Since I am starting out, I am not sure if this problem in throughout. Take the code:

StageOptions options = new StageOptions() ..backgroundColor = Color.White;

I cannot find documentation to support this particular syntax, so I find it, along with the other properties, very confusing. I would prefer something like this:

StageOptions options = new StageOptions() ..backgroundColor = White;

or even better: StageOptions options = new StageOptions() ..backgroundColor.Bisque; // would be better for auto-completion

or equally better StageOptions options = new StageOptions() ..backgroundColor(Bisque);

Not sure if this is possible, as there may be a specific reason for the syntax, but I am just not clear, so wanted to propose it, and this would apply to the other properties as well, and not just backgroundColor.

bp74 commented 6 years ago

Hi,

The ".." syntax is a feature of the Dart language, it is just a shorter version of this:

var stageOptions = StageXL.stageOptions;
stageOptions.renderEngine = RenderEngine.WebGL;
stageOptions.stageScaleMode = StageScaleMode.SHOW_ALL;
stageOptions.stageAlign = StageAlign.NONE;
stageOptions.backgroundColor = Color.Black;

If you would like do use colors like this ...

stageOptions.backgroundColor = Black;

... you would need to declare all colors at the root level. It is very bad practice to declare so many constants at the root level. Therefore all constants for colors are grouped as static properties of the Color class.

Hope this makes it a little bit clearer.

dashtodartlang commented 6 years ago

That makes a lot of sense, and thank you for explaining. I'll close this.