Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #77 from johanlajili/pauseRendering
Browse files Browse the repository at this point in the history
Allow to pause and resume rendering
  • Loading branch information
adireddy committed Jan 25, 2016
2 parents 31a1ff3 + f1e6536 commit 7b87ef8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/pixi/plugins/app/Application.hx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class Application {
public static inline var WEBGL:String = "webgl";

var _frameCount:Int;
var _animationFrameId:Null<Int>;

public function new() {
_setDefaultValues();
Expand All @@ -153,6 +154,7 @@ class Application {
}

inline function _setDefaultValues() {
_animationFrameId = null;
pixelRatio = 1;
skipFrame = false;
autoResize = true;
Expand Down Expand Up @@ -205,20 +207,23 @@ class Application {
if (roundPixels) renderer.roundPixels = true;

Browser.document.body.appendChild(renderer.view);
if (autoResize) Browser.window.onresize = _onWindowResize;
Browser.window.requestAnimationFrame(_onRequestAnimationFrame);

resumeRendering();
#if stats addStats(); #end
}

public function pauseRendering() {
Browser.window.onresize = null;
Browser.window.requestAnimationFrame(function(elapsedTime) {});
if (_animationFrameId != null){
Browser.window.cancelAnimationFrame(_animationFrameId);
_animationFrameId = null;
}
}

public function resumeRendering() {
if (autoResize) Browser.window.onresize = _onWindowResize;
Browser.window.requestAnimationFrame(_onRequestAnimationFrame);
if (_animationFrameId == null){
_animationFrameId = Browser.window.requestAnimationFrame(_onRequestAnimationFrame);
}
}

@:noCompletion function _onWindowResize(event:Event) {
Expand All @@ -238,7 +243,7 @@ class Application {
if (onUpdate != null) onUpdate(elapsedTime);
renderer.render(stage);
}
Browser.window.requestAnimationFrame(_onRequestAnimationFrame);
_animationFrameId = Browser.window.requestAnimationFrame(_onRequestAnimationFrame);
}

public function addStats() {
Expand Down

0 comments on commit 7b87ef8

Please sign in to comment.