-
Notifications
You must be signed in to change notification settings - Fork 456
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
Conversation
Increase readability.
Also, please change the template of Main.hx (Main.hx.tpl) into a static file (Main.hx). |
Added function
Also, try operators overloading? |
* @param scalar How much times this point will be as it before. | ||
* @return This point. | ||
*/ | ||
public function multiply(scalar:Float):FlxPoint |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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()
.
@@ -243,6 +243,14 @@ class FlxGame extends Sprite | |||
// Super high priority init stuff | |||
_inputContainer = new Sprite(); | |||
|
|||
if (GameSizeX == 0) |
There was a problem hiding this comment.
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.
Operator overloading only works for abstracts. I've experimented with it a bit once... You would need a Operator overloading might be supported via static extensions in Haxe 4 (HaxeFoundation/haxe#2803), which would be quite convenient. Of course, that's not gonna be available anytime soon. |
* @param k - scale coefficient | ||
* @return scaled vector | ||
*/ | ||
public inline function scale(k:Float):FlxVector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still returns a FlxVector
and says @return scaled vector
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this is going to result in sprite.scale.scale()
, which looks quite weird... Oh well.
* @param k - scale coefficient | ||
* @return scaled vector | ||
*/ | ||
public inline override function scale(k:Float):FlxVector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An inlined function can't be overriden. Are you actually compiling this code locally? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no. both with override or without override failed.
I tried this:
class A{
public static function main(){
new B().a();
}
}
class B extends C {
public **override** inline function a():B {
return this;
}
}
class C {
public inline function a():C {
return this;
}
}
with override
:
Field a is inlined and cannot be overridden
without:
Field a should be declared with 'override' since it is inherited from superclass C
wtf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that FlxPoint#scale()
is inline
- you can't override a function that is inline, otherwise the compiler wouldn't be able to inline it anymore.
You definitely can't omit the override keyword.
@@ -223,16 +223,16 @@ class FlxGame extends Sprite | |||
/** | |||
* Instantiate a new game object. | |||
* | |||
* @param GameSizeX The width of your game in game pixels, not necessarily final display pixels (see Zoom). | |||
* @param GameSizeY The height of your game in game pixels, not necessarily final display pixels (see Zoom). | |||
* @param GameSizeX The width of your game in game pixels, not necessarily final display pixels (see Zoom). If it is less than 0, HaxeFlixel will auto detect the width according to the current window. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These docs are not quite accurate, they only account for the < 0
case, not == 0
.
@@ -243,6 +243,14 @@ class FlxGame extends Sprite | |||
// Super high priority init stuff | |||
_inputContainer = new Sprite(); | |||
|
|||
if (GameSizeX <= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should stick to only == 0
. Something like new FlxGame(-10, -50, PlayState)
would result in windowSize x windowHeight, which seems a little weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't understand what do you mean by windowSize x windowHeight
.
Another reason I can think of is to reserve the negative values for possible more implements in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant windowWidth x windowHeight.
What I meant is that it seems confusing to the reader that random negative values would turn into a FlxGame
instance which uses the window dimensions, wheareas with 0
, you can at least guess that it probably has some special meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the comments, so it is easier to be understood.
Just think if somehow a negative value is passed in, FlxGame
can deal with it.
just keep both |
Why? I don't agree with that. Having two functions in |
@@ -243,6 +243,14 @@ class FlxGame extends Sprite | |||
// Super high priority init stuff | |||
_inputContainer = new Sprite(); | |||
|
|||
if (GameSizeX <= 0) | |||
{ | |||
GameSizeX = Std.int(Lib.current.stage.window.width); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
Well, if not, how to solve the "inline" problem? |
Yeah, just remove the |
OK.
What about |
Yeah, not a fan of that. |
Tested. works. see here