SaveCPU plugin not working... possible solution with this.game.lockRender
raimon-segura opened this issue · 4 comments
It seems that SaveCPU plugin won't work since version 2.2.0 because this change:
"Phaser.HEADLESS check removed from the core game loop. If you need to disable rendering you can now override the Phaser.Game.updateRender method instead with your own."
Using lockRender in setRender function seems to work, but I do not know if there is something else to consider.
Phaser.Plugin.SaveCPU.prototype.setRender = function () {
'use strict';
if (this.renderDirty) {
this.game.renderType = this.renderType;
this.game.lockRender = false;
} else {
this.game.renderType = Phaser.HEADLESS;
this.game.lockRender = true;
}
this.renderDirty = false;
};
Thanks!
Thanks for this suggestion, @raimon-segura! I just tried integrating the savecpu plugin and was wondering why it didn't seem to be working.
@photonstorm - Is @raimon-segura's updated code (above) an acceptable patch here?
Has anyone tested this fix yet? I also am trying to integrate this plugin but am not seeing a CPU or FPS reduction.
@photonstorm mentioned a possible way to fix this plugin using setTimeout at phaserjs/phaser#1968 (comment)
Hi,
This patch works for me several months ago, now it's not working... setting this.game.lockRender has no effect , maybe browsers updates broke this.
Another improvement for setRender... this checks if there are any tween running or not to change renderOnFPS, it doesn't works now but it save more cpu :)
Phaser.Plugin.SaveCPU.prototype.setRender = function () {
'use strict';
var tweens = this.game.tweens.getAll();
if (tweens.length>0){
this.renderOnFPS = 46;
}
else{
this.renderOnFPS = 12;
}
if (this.renderDirty) {
this.game.renderType = this.renderType;
this.game.lockRender = false;
} else {
this.game.renderType = Phaser.HEADLESS;
this.game.lockRender = true;
}
this.renderDirty = false;
};