语言

Menu
Sites
Language
Canvas Aplication

Hello devs.

I´m building a canvas web app and I tried to interruput the gameplay by simulating a calling.

I configured it to background-support disable since i want to stop the render once it is not on the screen for the user.

Unfornutately the canvas remain rendering, but the documentation says:

"When a Web application is sent to the background or hidden, the JavaScript execution and rendering, including CSS animations, is suspended, unless the application is specifically configured to be a background service."

 

Anyone knows if and how I can intercept or listen the event that some calling is happening to control the render to stop and to know that it has been finished to let it keeping update?

Thanks in advance.

Vinicius

编辑者为: Brock Boland 17 3月, 2014 原因: Paragraph tags added automatically from tizen_format_fix module.

响应

6 回复
Alexander AVSukhov
Hi, Try to use visibilitychange event. When your web application that support background mode goes to background, this event is sent to your web application. Using this event, your application can know when it goes to background and you can stop/start animation in the handler for this event.
Vinicius Araujo Vieira
Thanks for the answer Alexander. Unfortunately it didint solve the problem. The event doesnt fire: //////////////////////////////////////////////////////////////////////////// if (typeof document.hidden !== "undefined") { hidden = "hidden"; visibilityChange = "visibilitychange"; } else if (typeof document.mozHidden !== "undefined") { hidden = "mozHidden"; visibilityChange = "mozvisibilitychange"; } else if (typeof document.msHidden !== "undefined") { hidden = "msHidden"; visibilityChange = "msvisibilitychange"; } else if (typeof document.webkitHidden !== "undefined") { hidden = "webkitHidden"; visibilityChange = "webkitvisibilitychange"; } document.addEventListener(visibilityChange, handleVisibilityChange, false); function handleVisibilityChange() { if(document.hidden) { paused = true; }else{ paused = false; } } /////////////////////////////////////////////// Any other clues?
Vinicius Araujo Vieira
I tryed to use jquery bind to do and the result was the same. =\
Vinicius Araujo Vieira
I noticed that if you have a interval on window it keeps runing if you are on a phone call. This should be automatically sttoped according to Tizen documentation.
Vinicius Araujo Vieira
So anyone has this solved? Im currently using easelJs and have a canvas game with background support set to disable. Im trying to listen to visibilyty change event and focus event, but on web simulator i made a call and the game keeps going on. None of listeners below trigger if I get a incoming call in web simulator. document.addEventListener("visibilitychange", onVisibilityChanged, false); document.addEventListener("mozvisibilitychange", onVisibilityChanged, false); document.addEventListener("webkitvisibilitychange", onVisibilityChanged, false); document.addEventListener("msvisibilitychange", onVisibilityChanged, false); $("#gameArea").focusin(function () { console.log("received focus In Event"); }) $("#gameArea").focusout(function () { console.log("received focus Out Event"); }) function onVisibilityChanged() { console.log("visibilite change event"); }
Vinicius Araujo Vieira
So im adding a solution. Visibility is not working but i found a coment by by Byron Gavras, here(https://developer.tizen.org/forums/web-application-development/how-check-home-button-press) and this actually worked fine for me. window.onblur = function() { console.log("blurred window"); } window.onfocus = function() { console.log("focus); }