Skip to content

Commit af86b69

Browse files
committed
Added Ticker.maxDelta
Signed-off-by: Grant Skinner <info@gskinner.com>
1 parent 4ba99df commit af86b69

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

VERSIONS.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ DEPRECATED (will be removed in a future version):
2121
- SpriteSheetUtils.mergeAlpha()
2222

2323
*****
24-
Other changes:
24+
OTHER:
2525
- implemented createjs Utils
2626
- implemented "use strict" mode
2727
- BitmapAnimation renamed to Sprite
@@ -56,6 +56,7 @@ Other changes:
5656
- DisplayObject, SpriteSheet, and SpriteSheetBuilder now inherit from EventDispatcher
5757
- fixed an issue with the tick event's time value being epoch time instead of Timer time
5858
- added Ticker.getEventTime()
59+
- added Ticker.maxDelta
5960
- the initialize methods for Point, Rectangle, and Matrix2D are now public
6061
- added .copy() to Point, Rectangle, and Matrix2D
6162
- fixed an issue that could occur when reinitializing Matrix2D

src/easeljs/utils/Ticker.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,23 @@ var Ticker = function() {
160160
**/
161161
Ticker.timingMode = null;
162162

163+
/**
164+
* Specifies a maximum value for the delta property in the tick event object. This is useful when building time
165+
* based animations and systems to prevent issues caused by large time gaps caused by background tabs, system sleep,
166+
* alert dialogs, or other blocking routines. Double the expected frame duration is often an effective value
167+
* (ex. maxDelta=50 when running at 40fps).
168+
*
169+
* This does not impact any other values (ex. time, runTime, etc), so you may experience issues if you enable maxDelta
170+
* when using both delta and other values.
171+
*
172+
* If 0, there is no maximum.
173+
* @property maxDelta
174+
* @static
175+
* @type {number}
176+
* @default 0
177+
*/
178+
Ticker.maxDelta = 0;
179+
163180
// mix-ins:
164181
// EventDispatcher methods:
165182
Ticker.removeEventListener = null;
@@ -547,8 +564,9 @@ var Ticker = function() {
547564

548565
if (Ticker.hasEventListener("tick")) {
549566
var event = new createjs.Event("tick");
567+
var maxDelta = Ticker.maxDelta;
568+
event.delta = (maxDelta && elapsedTime > maxDelta) ? maxDelta : elapsedTime;
550569
event.paused = paused;
551-
event.delta = elapsedTime;
552570
event.time = time;
553571
event.runTime = time-Ticker._pausedTime;
554572
Ticker.dispatchEvent(event);

0 commit comments

Comments
 (0)