@@ -505,6 +505,7 @@ class FlxTween implements IFlxDestroyable
505505 public var active (default , set ): Bool = false ;
506506 public var duration : Float = 0 ;
507507 public var ease : EaseFunction ;
508+ public var framerate : Null <Float >;
508509 public var onStart : TweenCallback ;
509510 public var onUpdate : TweenCallback ;
510511 public var onComplete : TweenCallback ;
@@ -562,6 +563,7 @@ class FlxTween implements IFlxDestroyable
562563 onUpdate = Options .onUpdate ;
563564 onComplete = Options .onComplete ;
564565 ease = Options .ease ;
566+ framerate = Options .framerate ;
565567 setDelays (Options .startDelay , Options .loopDelay );
566568 this .manager = manager != null ? manager : globalManager ;
567569 }
@@ -619,13 +621,22 @@ class FlxTween implements IFlxDestroyable
619621
620622 function update (elapsed : Float ): Void
621623 {
622- _secondsSinceStart + = elapsed ;
624+ var preTick : Float = _secondsSinceStart ;
625+ var postTick : Float = (_secondsSinceStart + = elapsed );
626+
623627 var delay : Float = (executions > 0 ) ? loopDelay : startDelay ;
624628 if (_secondsSinceStart < delay )
625629 {
626630 return ;
627631 }
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 ;
629640 if (ease != null )
630641 {
631642 scale = ease (scale );
@@ -647,7 +658,7 @@ class FlxTween implements IFlxDestroyable
647658 }
648659 else
649660 {
650- if (onUpdate != null )
661+ if (postTick > preTick && onUpdate != null )
651662 onUpdate (this );
652663 }
653664 }
@@ -919,6 +930,12 @@ typedef TweenOptions =
919930 */
920931 @:optional var ease : EaseFunction ;
921932
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+
922939 /**
923940 * Optional start callback function.
924941 */
0 commit comments