play animation only if is visible

pull/14/head
Patricio Gonzalez Vivo 9 years ago
parent ac2658a92b
commit 3163df5f01

@ -25,6 +25,11 @@ var timeLoad = Date.now();
var mouse = {x: 0, y: 0}; var mouse = {x: 0, y: 0};
var billboards = []; var billboards = [];
function isCanvasVisible(_canvas){
return ((_canvas.getBoundingClientRect().top + _canvas.height) > 0) &&
(_canvas.getBoundingClientRect().top < (window.innerHeight || document.documentElement.clientHeight));
}
function isPowerOf2(value) { function isPowerOf2(value) {
return (value & (value - 1)) == 0; return (value & (value - 1)) == 0;
}; };
@ -206,7 +211,8 @@ function renderShaders(){
for(var i = 0; i < billboards.length; i++){ for(var i = 0; i < billboards.length; i++){
// If there is something on the billboard // If there is something on the billboard
if( billboards[i] !== undefined ){ if( billboards[i] !== undefined ){
if ( billboards[i].animated === true ){ if ( billboards[i].animated === true &&
isCanvasVisible(billboards[i].canvas )){
renderShader( billboards[i] ); renderShader( billboards[i] );
} }
} }

Loading…
Cancel
Save