FlxCamera question

48 views
Skip to first unread message

Peter K.

unread,
Apr 29, 2015, 1:12:48 PM4/29/15
to haxef...@googlegroups.com


Hey guys,

I'm really curious why isn't the FlxCamera's style's type an enum? Haxe supports that type, so I don't see why it shouldn't be an Enum. I have checked the FlxCamera class, and it seems that their only reason to exist is to switch between style states. Same goes to the SHAKE.

For example, the shake:
if ((_fxShakeDirection == SHAKE_BOTH_AXES) || (_fxShakeDirection == SHAKE_HORIZONTAL_ONLY))
{
_fxShakeOffset.x = (FlxRandom.float() * _fxShakeIntensity * width * 2 - _fxShakeIntensity * width) * zoom;
}
if ((_fxShakeDirection == SHAKE_BOTH_AXES) || (_fxShakeDirection == SHAKE_VERTICAL_ONLY))
{
_fxShakeOffset.y = (FlxRandom.float() * _fxShakeIntensity * height * 2 - _fxShakeIntensity * height) * zoom;
}

It would be way better to have an ENUM of the possible shakes and follow styles. 

Style in the "follow" function:
switch (Style)
{
case STYLE_PLATFORMER:
var w:Float = (width / 8) + (Offset != null ? Offset.x : 0);
var h:Float = (height / 3) + (Offset != null ? Offset.y : 0);
deadzone = FlxRect.get((width - w) / 2, (height - h) / 2 - h * 0.25, w, h);
case STYLE_TOPDOWN:
helper = Math.max(width, height) / 4;
deadzone = FlxRect.get((width - helper) / 2, (height - helper) / 2, helper, helper);
case STYLE_TOPDOWN_TIGHT:
helper = Math.max(width, height) / 8;
deadzone = FlxRect.get((width - helper) / 2, (height - helper) / 2, helper, helper);
case STYLE_LOCKON:
if (target != null) 
{
w = target.width + (Offset != null ? Offset.x : 0);
h = target.height + (Offset != null ? Offset.y : 0);
}
deadzone = FlxRect.get((width - w) / 2, (height - h) / 2 - h * 0.25, w, h);
case STYLE_SCREEN_BY_SCREEN:
deadzone = FlxRect.get(0, 0, width, height);
default:
deadzone = null;
}

It wouldn't really improve the performance significantly, it is more about readability.

I would rather write
FlxCamera.follow(someTarget, FlxCameraFollowStyles.STYLE_LOCK_ON);
than
FlxCamera.follow(someTarget, 0);

Same goes to:
shake(0.05, 0.5, someOnCompleteFunction, true, FlxCameraShakeDirections.SHAKE_BOTH_AXES);

than
shake(0.05, 0.5, someOnCompleteFunction, true, 0);

Yes, I realize that the project is Open Source.

So my questions are:
-Wouldn't it be better with an Enum?
-Is it possible that we might see more Enums in HaxeFlixel?

SruloArt

unread,
Apr 30, 2015, 4:37:27 AM4/30/15
to haxef...@googlegroups.com
It's already been done: https://github.com/HaxeFlixel/flixel/blob/dev/flixel/FlxCamera.hx :)
You should really follow the Github repo (https://github.com/HaxeFlixel) and upgrade to the dev branches if you're interested in the framework itself, and yes, plenty of more enums!
Reply all
Reply to author
Forward
0 new messages