-
Notifications
You must be signed in to change notification settings - Fork 469
FlxTween framerate option #3372
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
base: dev
Are you sure you want to change the base?
Conversation
I think you could change the capitilzation to "frameRate" in favor of FlxAnimation |
good to be consistent, but it seems flixel is already inconsistent on this https://github.com/search?q=repo%3AHaxeFlixel%2Fflixel%20framerate&type=code |
fair enough, that works too |
@@ -505,6 +505,7 @@ class FlxTween implements IFlxDestroyable | |||
public var active(default, set):Bool = false; | |||
public var duration:Float = 0; | |||
public var ease:EaseFunction; | |||
public var framerate:Null<Float>; |
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.
Let's use a float where 0 means "an infinite rate "
public var framerate:Null<Float>; | |
public var framerate:Float; |
@@ -562,6 +563,7 @@ class FlxTween implements IFlxDestroyable | |||
onUpdate = Options.onUpdate; | |||
onComplete = Options.onComplete; | |||
ease = Options.ease; | |||
framerate = Options.framerate; |
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.
framerate = Options.framerate; | |
framerate = Options.framerate != null ? Options.framerate : 0; |
var delay:Float = (executions > 0) ? loopDelay : startDelay; | ||
if (_secondsSinceStart < delay) | ||
{ | ||
return; | ||
} | ||
scale = Math.max((_secondsSinceStart - delay), 0) / duration; | ||
|
||
if (framerate != null && framerate > 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.
if (framerate != null && framerate > 0) | |
if (framerate > 0) |
* This also affects how often `onUpdate` is called. | ||
* Not to be confused with `period` for flickering. | ||
*/ | ||
@:optional var framerate:Float; |
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.
nit picky, but I'm trying to use Null whenever it's implied
@:optional var framerate:Float; | |
@:optional var framerate:Null<Float>; |
var preTick:Float = _secondsSinceStart; | ||
var postTick:Float = (_secondsSinceStart += elapsed); |
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.
var preTick:Float = _secondsSinceStart; | |
var postTick:Float = (_secondsSinceStart += elapsed); | |
var preTick:Float = _secondsSinceStart; | |
_secondsSinceStart += elapsed | |
var postTick:Float = _secondsSinceStart; |
* Optional set framerate for this tween to update at. | ||
* This also affects how often `onUpdate` is called. | ||
*/ | ||
@:optional var framerate:Float; |
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.
@:optional var framerate:Float; | |
@:optional var framerate:Null<Float>; |
var tweenUpdatesDefault:Int = 0; | ||
var tweenDefault:FlxTween = FlxTween.tween(this, {value: 1000}, 2, {startDelay: 0.54321, onUpdate: function(_) tweenUpdatesDefault++}); | ||
step(FlxG.updateFramerate * 3); // 3 full seconds | ||
Assert.areEqual(FlxG.updateFramerate * 2, tweenUpdatesDefault); | ||
|
||
// various tween framerate values | ||
var testFramerates:Array<Float> = [5, 10, 10.1, 24, 29.9, 30, 30.1, 31, 59.9, 60, 100]; | ||
for (framerate in testFramerates) | ||
{ | ||
var tweenUpdates:Int = 0; | ||
var tween:FlxTween = FlxTween.tween(this, {value: 1000}, 2, {startDelay: 0.54321, framerate: framerate, onUpdate: function(_) tweenUpdates++}); | ||
step(FlxG.updateFramerate * 3); // 3 full seconds | ||
Assert.areEqual(Std.int(Math.ceil(Math.min(framerate, FlxG.updateFramerate) * 2)), tweenUpdates); | ||
} | ||
} |
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's a little difficult to understand what this is testing, and generally, we should assert against literal values rather than an equation. Also try to avoid "throwing the kitchen sink" at every test, make it very obvious what each test covers and why it's needed
Example (untested):
function assertTweenUpdates(duration:Float, ?fps:Float, ?options:TweenOptions, expected:Int)
{
var updates = 0;
if (options)
options = {};
if (fps != null)
options. framerate = fps;
options.onUpdate = function(_) updates++;
options.onComplete = function(_) Assert.areEqual(expected, updates);
FlxTween.tween({value: 0.0}, {value: 1}, 2.0, options);
}
assertTweenUpdates(2.0, null, null, 60);
assertTweenUpdates(2.0, 0, null, 60);
assertTweenUpdates(2.0, 5, null, 10);
assertTweenUpdates(2.0, 10, { startDelay: 0.5 }, 20);
assertTweenUpdates(2.0, 10.1, null, 21);
assertTweenUpdates(2.0, 29.9, null, 60);
assertTweenUpdates(2.0, 100, null, 60);
//... other edge cases
step(FlxG.updateFramerate * 3); // 3 full seconds
implements / closes #3367