How do I work device button 'back' in game?

Get help using Construct 2

Post » Fri Jul 04, 2014 9:06 am

I make a such game.
I need when you press a button 'back' on the device then user will go to the previous scene , and if it is the first page (level or Layout),user would be exiting of the game ('exit').
in principle at tizen sdk it's done in folder js - main.js and it


Code: Select all
var init = function () {
    // TODO:: Do your initialization job
    console.log("init() called");

    // add eventListener for tizenhwkey
    document.addEventListener('tizenhwkey', function(e) {
        if(e.keyName == "back")
            tizen.application.getCurrentApplication().exit();
    });
};


Image



However,C2 ignores it somehow (main.js) , namely probably as follows:
file index:

Code: Select all
// Pause and resume on page becoming visible/invisible
      function onVisibilityChanged() {
         if (document.hidden || document.mozHidden || document.webkitHidden || document.msHidden)
            cr_setSuspended(true);
         else
            cr_setSuspended(false);
      };
      
      document.addEventListener("visibilitychange", onVisibilityChanged, false);
      document.addEventListener("mozvisibilitychange", onVisibilityChanged, false);
      document.addEventListener("webkitvisibilitychange", onVisibilityChanged, false);
      document.addEventListener("msvisibilitychange", onVisibilityChanged, false);
      
    </script>

Image
Question - How to make exit of the game on the first page of the game by clicking the back button device, and in other cases would go to the previous page game (Layout)?
B
16
S
4
G
1
Posts: 60
Reputation: 1,131

Post » Fri Jul 04, 2014 3:40 pm

Somebody help us......I have this doubt too....
Image
B
32
S
7
Posts: 197
Reputation: 2,527

Post » Fri Jul 04, 2014 3:46 pm

@shukra @Harishankar

Add the Browser object and then use Browser->On Back button to detect when the devices back button is pressed.

Manual wrote:On back button
Triggered when the user presses the device's 'Back' button. Note not all devices have this button (e.g. iOS devices only have a 'Home' button) and not all platforms support this trigger.


Detecting when on the first page or other page you could do using a System->Compare two values with one being the in-built value LayerName, if you don't have separate Event Sheets for the menu and levels.

You could use a Global variable to track the last layout (that is, before you load a layout, set the Global variable to the current layout name), and use System->Go to layout to load it.

You might be able to use Browser->Close to exit the app
Find all the Construct 2 games that were on Steam Greenlight here
B
35
S
9
G
7
Posts: 467
Reputation: 6,864

Post » Fri Jul 04, 2014 7:56 pm

yes..
Browser -> on back bottom pressed = Browser -> close window ( Go to...)

cool
B
16
S
4
G
1
Posts: 60
Reputation: 1,131

Post » Fri Jul 04, 2014 8:26 pm

@OddConfection
May be you can help me in this tema -
How to make display on the device is not screen off

viewtopic.php?f=147&t=108792
B
16
S
4
G
1
Posts: 60
Reputation: 1,131


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests