Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

It still doesn't work, this is my code

declare let document;
let inGameMusicPlayer = new Sup.Audio.SoundPlayer("Sound", 1.0, { loop: true });


class MouseCoordsBehavior extends Sup.Behavior {

update() {
// Mouse coordinates returned by .getMousePosition() are normalized to (-1, 1)
let { x, y } = Sup.Input.getMousePosition();
x = (x + 1) / 2 * Sup.Input.getScreenSize().x;
y = (1 - (y + 1) / 2) * Sup.Input.getScreenSize().y;

this.actor.textRenderer.setText(`X = ${Math.round(x)}\nY = ${Math.round(y)}`);

if (x >= 0 && x <= 170 && y >= 0 && y <= 170 && Sup.Input.wasMouseButtonJustReleased(0)) {
this.actor.textRenderer.setText("OMG BUTTONS");
handleVisibilityChange();
}


}
}
Sup.registerBehavior(MouseCoordsBehavior);
function handleVisibilityChange() {
if (document.hidden) inGameMusicPlayer.pause();
else inGameMusicPlayer.play();
}
document.addEventListener("webkitvisibilitychange", handleVisibilityChange, false);

Does it work if you test on a browser on your PC ? It should work when you switch tab.

What browser do you use on your phone ?

Do you still have any error ? If yes, can you post them ?

(1 edit)

It doesn't work when I switch tab, I'm trying to run it as a native Android app using Intel XDK to build it

And nope, no errors. Code compiles perfectly fine

(1 edit)

Do you have Chrome installed on your phone ? Can you try accessing a build directly from the browser instead of the packaged version ?

EDIT: Maybe this page can be of some help ? http://caniuse.com/#feat=pagevisibility
I needed the webkit prefix to make it work on my phone but maybe you don't ?

It seems to work on Chrome, is there a reason why it doesn't work on Firefox or on the packaged version?

For the packaged version, it depends on which version of Chrome is packaged along. For firefox, it may work if you remove the "webkit" prefix ?

(1 edit) (+1)

Would building it with Crosswalk solve this problem?

Edit: Bundling the app with Crosswalk seems to make this work! Thanks a bunch!

Deleted 8 years ago