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

0 favourites
  • 5 posts
From the Asset Store
Helping streamers give their viewers more excitement.
  • 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

    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();
        });
    };[/code:27lcux2t]
    
    [img="http://c2community.ru/imagehosting/images/2014/Jul/04/1.jpg"]
    
    However,C2  ignores it somehow (main.js) , namely probably as follows:
      file index:
    
    [code:27lcux2t]// 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>[/code:27lcux2t]
    [img="http://c2community.ru/imagehosting/images/2014/Jul/04/2.jpg"]
    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)?
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Somebody help us......I have this doubt too....

  • shukra

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

    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

  • yes..

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

    cool

  • OddConfection

    May be you can help me in this tema -

    How to make display on the device is not screen off

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)