@@ -505,6 +505,7 @@ class FlxTween implements IFlxDestroyable
505
505
public var active (default , set ): Bool = false ;
506
506
public var duration : Float = 0 ;
507
507
public var ease : EaseFunction ;
508
+ public var framerate : Null <Float >;
508
509
public var onStart : TweenCallback ;
509
510
public var onUpdate : TweenCallback ;
510
511
public var onComplete : TweenCallback ;
@@ -562,6 +563,7 @@ class FlxTween implements IFlxDestroyable
562
563
onUpdate = Options .onUpdate ;
563
564
onComplete = Options .onComplete ;
564
565
ease = Options .ease ;
566
+ framerate = Options .framerate ;
565
567
setDelays (Options .startDelay , Options .loopDelay );
566
568
this .manager = manager != null ? manager : globalManager ;
567
569
}
@@ -619,13 +621,22 @@ class FlxTween implements IFlxDestroyable
619
621
620
622
function update (elapsed : Float ): Void
621
623
{
622
- _secondsSinceStart + = elapsed ;
624
+ var preTick : Float = _secondsSinceStart ;
625
+ var postTick : Float = (_secondsSinceStart + = elapsed );
626
+
623
627
var delay : Float = (executions > 0 ) ? loopDelay : startDelay ;
624
628
if (_secondsSinceStart < delay )
625
629
{
626
630
return ;
627
631
}
628
- scale = Math .max ((_secondsSinceStart - delay ), 0 ) / duration ;
632
+
633
+ if (framerate != null && framerate > 0 )
634
+ {
635
+ preTick = Math .fround (preTick * framerate ) / framerate ;
636
+ postTick = Math .fround (postTick * framerate ) / framerate ;
637
+ }
638
+
639
+ scale = Math .max ((postTick - delay ), 0 ) / duration ;
629
640
if (ease != null )
630
641
{
631
642
scale = ease (scale );
@@ -647,7 +658,7 @@ class FlxTween implements IFlxDestroyable
647
658
}
648
659
else
649
660
{
650
- if (onUpdate != null )
661
+ if (postTick > preTick && onUpdate != null )
651
662
onUpdate (this );
652
663
}
653
664
}
@@ -919,6 +930,12 @@ typedef TweenOptions =
919
930
*/
920
931
@:optional var ease : EaseFunction ;
921
932
933
+ /**
934
+ * Optional set framerate for this tween to update at.
935
+ * This also affects how often `onUpdate` is called.
936
+ */
937
+ @:optional var framerate : Float ;
938
+
922
939
/**
923
940
* Optional start callback function.
924
941
*/
0 commit comments