I'm working on a game for WP8.1. gameJS library uses some kind of Yabble.js. The html page with the game canvas contains the following code:
WinJS.UI.Pages.define("/pages/game/game.html", {
ready: function (element, options) {
require.setModuleRoot('/js/');
require.run('main');
}
});
The main.js file contains the main game loop and all other game stuff. So, when I first navigate to game.html, then everything works fine. But if I go away from game.html and then go to this page again (for example using back button) I can see only white screen.
I can see in debugger that the main.js runs again and seems like it causes this trouble. Two game loops just collide each other. How to completely terminate and unload main.js when user goes away from game.html? Or how to check is there a main.js module already runned to prevent it from second running?
> WinJS' ready function fires every time, when I go to the page.
Is there a way to detect whether the script is "waking up" (e.g. from navigating back to it) or being freshly started? That could help.
> I'm not sure that WinJS has integrated way to run commonjs modules asynchronously. I'll try to search the info about it, but I think It will not solve the problem.
It seems to me winjs is using AMD modules? or at least it's possible to use requirejs with winjs afaict from http://blogs.msdn.com/b/dave_crooks_dev_blog/archive/2014/01/17/requirejs-windows-8-winjs-and-cross-platform.aspx
you can convert GameJs commonjs into AMD like so: http://requirejs.org/docs/commonjs.html#autoconversion maybe that's easier.
simon
> --
> You received this message because you are subscribed to the Google Groups "GameJs" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to gamejs+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
WinJS.UI.Pages.define("/pages/game/game.html", { ready: function (element, options) { require.setModuleRoot('/js/'); require.run('main');
WinJS.Application.onbackclick = function (evt) { WinJS.Application.stop(); } } });
gamejs.onTick(function (msDuration) {
//game loop logic
});