Added in forceSetTimeout fps value (#4179)

This commit is contained in:
Richard Davey 2019-11-18 16:23:29 +00:00
parent 360640e4de
commit cc6cec5c83
3 changed files with 18 additions and 3 deletions

View file

@ -11,6 +11,7 @@
* `Tilemap.getImageLayerNames` is a new method that returns a list of all valid imagelayer names loaded in the Tilemap (thanks @Olliebrown)
* `Tilemap.getObjectLayerNames` is a new method that returns a list of all valid objectgroup names loaded in the Tilemap (thanks @Olliebrown)
* `Tilemap.getTileLayerNames` is a new method that returns a list of all valid tilelayer names loaded in the Tilemap (thanks @Olliebrown)
* When `forceSetTimeOut` is set to `true` in the Game Config, you can now set the target frame rate by setting the `fps.target` value (thanks @pavels)
### Updates

View file

@ -447,7 +447,7 @@ var TimeStep = new Class({
this.callback = callback;
this.raf.start(this.step.bind(this), this.forceSetTimeOut);
this.raf.start(this.step.bind(this), this.forceSetTimeOut, this._target);
},
/**

View file

@ -82,6 +82,17 @@ var RequestAnimationFrame = new Class({
*/
this.lastTime = 0;
/**
* The target FPS rate in ms.
* Only used when setTimeout is used instead of RAF.
*
* @name Phaser.DOM.RequestAnimationFrame#target
* @type {number}
* @default 0
* @since 3.21.0
*/
this.target = 0;
var _this = this;
/**
@ -119,7 +130,7 @@ var RequestAnimationFrame = new Class({
{
var d = Date.now();
var delay = Math.max(16 + _this.lastTime - d, 0);
var delay = Math.min(Math.max(_this.target * 2 + _this.tick - d, 0), _this.target);
_this.lastTime = _this.tick;
@ -139,8 +150,9 @@ var RequestAnimationFrame = new Class({
*
* @param {FrameRequestCallback} callback - The callback to invoke each step.
* @param {boolean} forceSetTimeOut - Should it use SetTimeout, even if RAF is available?
* @param {number} targetFPS - The target fps rate (in ms). Only used when setTimeout is used.
*/
start: function (callback, forceSetTimeOut)
start: function (callback, forceSetTimeOut, targetFPS)
{
if (this.isRunning)
{
@ -151,6 +163,8 @@ var RequestAnimationFrame = new Class({
this.isSetTimeOut = forceSetTimeOut;
this.target = targetFPS;
this.isRunning = true;
this.timeOutID = (forceSetTimeOut) ? window.setTimeout(this.stepTimeout, 0) : window.requestAnimationFrame(this.step);