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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -