phaserjs / phaser-ce-plugins

For Phaser related Plugins
206 stars 56 forks source link

SaveCPU plugin not working... possible solution with this.game.lockRender #10

Open raimon-segura opened 9 years ago

raimon-segura commented 9 years ago

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!

gabehollombe commented 9 years ago

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?

JoeDuncko commented 9 years ago

Has anyone tested this fix yet? I also am trying to integrate this plugin but am not seeing a CPU or FPS reduction.

JoeDuncko commented 9 years ago

@photonstorm mentioned a possible way to fix this plugin using setTimeout at https://github.com/photonstorm/phaser/issues/1968#issuecomment-127795296

raimon-segura commented 8 years ago

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; };