javascript settimeout on Android context switch -


in javasscript, use settimeout repeatedly redraw html5 canvas.

function dodraw() {    drawoncanvas();    settimeout(dodraw, 20);  } 

i have problem on android browser. (perhaps on ios, haven't tested yet...) : 1. runs ok 2. press android "home" button , someting else 3. come browser. 4. problem: settimeout not scheduled execute again.

so screen refresh loop stops, , game "dead".

edit: now, continued investigating. turns out settimeout still works. real problem canvas disapeard screen, , nothing draw shows. canvas blank.

for rendering loops advised use requestanimationframe because knows when schedule callback, best possible time slot in browser repaint completed. using settimeout skip frames , that'll result in serious jankyy animation

and far question concerned can restart loop on document load

window.onload = function() {dodraw();}

i hope works .


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -