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

Auto detect window size and etc. #1811

Merged
merged 22 commits into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions flixel/FlxGame.hx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class FlxGame extends Sprite
* @param SkipSplash Whether you want to skip the flixel splash screen in FLX_NO_DEBUG or not.
* @param StartFullscreen Whether to start the game in fullscreen mode (desktop targets only), false by default
*/
public function new(GameSizeX:Int = 640, GameSizeY:Int = 480, ?InitialState:Class<FlxState>, Zoom:Float = 1, UpdateFramerate:Int = 60, DrawFramerate:Int = 60, SkipSplash:Bool = false, StartFullscreen:Bool = false)
public function new(GameSizeX:Int = 0, GameSizeY:Int = 0, ?InitialState:Class<FlxState>, Zoom:Float = 1, UpdateFramerate:Int = 60, DrawFramerate:Int = 60, SkipSplash:Bool = false, StartFullscreen:Bool = false)
{
super();

Expand All @@ -243,6 +243,14 @@ class FlxGame extends Sprite
// Super high priority init stuff
_inputContainer = new Sprite();

if (GameSizeX == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The special meaning of 0 for GameSizeX and GameSizeY should be documented in the @param docs.

{
GameSizeX = Std.int(Lib.current.stage.window.width);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be shorter / nicer to use FlxG.stage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way. FlxG is not initailized at that time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that matters? get_stage() is just a shortcut for Lib.current.stage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use .window here, needs to be stageWidth and stageHeight (Travis is currently failing because Stage#window doesn't exist in OpenFL legacy).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried using Lib.current.stage.width but not Lib.current.stage.*window*.width.
BUT, Lib.current.stage.width IS 0! I don't know why.
I figured that out when targeting flash.
Oh, also it is a reason not to use FlxG.stage.width.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stage.stageWidth, not stage.width.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I thought they are the same.
stage.stageWidth does work.

}
if (GameSizeY == 0)
{
GameSizeY = Std.int(Lib.current.stage.window.height);
}
// Basic display and update setup stuff
FlxG.init(this, GameSizeX, GameSizeY, Zoom);

Expand Down Expand Up @@ -561,7 +569,7 @@ class FlxGame extends Sprite

if (_skipSplash || FlxSplash.nextState != null) // already played
{
_requestedState = cast Type.createInstance(_initialState, []);
_requestedState = cast (Type.createInstance(_initialState, []));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be any parens here, cast is not a function.

if (FlxSplash.nextState == null)
{
_gameJustStarted = true;
Expand Down
15 changes: 14 additions & 1 deletion flixel/math/FlxPoint.hx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ class FlxPoint implements IFlxPooled
return this;
}

/**
* Multiply this point by a scalar.
*
* @param scalar How much times this point will be as it before.
* @return This point.
*/
public function multiply(scalar:Float):FlxPoint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FlxVector#scale() is the same thing, so this seems redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not redundant.
Some of HaxeFlixel's code use FlxPoint instead of FlxVector.
So you have to write code like this:

point.x*=scalar;
point.y*=scalar;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware, that doesn't make it any less redundant - both functions have the same implementation. Since FlxVector extends FlxPoint, FlxVector would have a scale() and a multiply().

If anything, scale() should be moved to FlxPoint().

{
x *= scalar;
y *= scalar;
return this;
}

/**
* Helper function, just copies the values from the specified point.
*
Expand Down Expand Up @@ -358,7 +371,7 @@ class FlxPoint implements IFlxPooled
{
angle = c2 - c1 * ((x + ay) / (ay - x));
}
angle = ((y < 0) ? -angle : angle) * FlxAngle.TO_DEG;
angle = ((y < 0) ? - angle : angle) * FlxAngle.TO_DEG;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidentally reformatted?


if (angle > 90)
{
Expand Down
4 changes: 2 additions & 2 deletions flixel/text/FlxText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1062,10 +1062,10 @@ class FlxTextFormat
private var format(default, null):TextFormat;

/**
* @param FontColor Set the font color. By default, inherits from the default format.
* @param FontColor Set the font color, in 0xRRGGBB format. By default, inherits from the default format.
* @param Bold Set the font to bold. The font must support bold. By default, false.
* @param Italic Set the font to italics. The font must support italics. Only works in Flash. By default, false.
* @param BorderColor Set the border color. By default, no border (null / transparent).
* @param BorderColor Set the border color, in 0xAARRGGBB format. By default, no border (null / transparent).
*/
public function new(?FontColor:FlxColor, ?Bold:Bool, ?Italic:Bool, ?BorderColor:FlxColor)
{
Expand Down