In iOS App, Controller not taking click on right side of screen

102 Views Asked by At

I created a simple controller.html for my AirConsole application. The content of which are as follows:

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta content='width=device-width, initial-scale=1, maximum-scale=1 user-scalable=0' name='viewport'>
        <title>AirConsole Controller</title>
        <link href='https://fonts.googleapis.com/css?family=Play:400,700' rel='stylesheet' type='text/css'>
        <!-- 3rd Party Libs -->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
        <!-- AIRCONSOLE -->
        <script type="text/javascript" src="https://www.airconsole.com/api/airconsole-latest.js"></script>
        <script type="text/javascript" src="controller/libs/airconsole_view_manager.js"></script>
        <script>
            var airConsole = null;
            var viewManager = null;
            var deviceId = null;
            var isReady = false;
            var isLoadingActive = true;
            /**
              * Sets up the communication to the screen.
              */
            function init() {
                airConsole = new AirConsole ( { orientation: AirConsole.ORIENTATION_LANDSCAPE } );
                airConsole.onMessage = function ( from, data ) {
                    if ( data.action == "REMOVE_LOADING" ) {
                        if ( isLoadingActive ) {
                            isLoadingActive = false;
                            showScreen ( "Ready" );
                        }
                    } else if (data.action == "SHOW_READY_SCREEN") {
                        showScreen ( "Ready" );
                    } else if ( data.action == "READY_RECEIVED") {
                        deviceId = data.info.deviceId;
                        showScreen ( "DoneReady" );
                    } else if ( data.action == "GAME_STARTED" ) {
                        showScreen ( "Waiting" );
                    } else if ( data.action == "START_GAME" ) {
                        showScreen ( "Controls" );
                    } else if (data.action == "GAME_END") {
                        showScreen ( "PerformEndGame" );
                    } else {
                        alert ( "Message: " + data.info.deviceId );
                    }
                }

                airConsole.onActivePlayersChange = function ( player_number ) {
                    // alert ( "Active Players Change" );
                } 

                airConsole.onReady = function () {
                    // alert ( "On Ready" );
                    viewManager = new AirConsoleViewManager ( airConsole );
                }

                // Listen for view changes
                airConsole.onCustomDeviceStateChange = function ( deviceId, data ) {
                    viewManager.onViewChange ( data, function ( view_id ) {
                        // view has changed
                        alert ( "VIEW MANAGER WORKING" );
                    } ); 
                };

                airConsole.onConnect = function ( id ) {
                    //alert ( "Device ID RECEIVED: " + id );
                    isReady = false;
                }

                airConsole.onGameEnd = function () {
                    alert ( "On Game End" );
                }
            }
        </script>
        <style type="text/css">
            *{
                padding: 0px;
                margin: 0px auto;
            }

            html, body {
                -ms-user-select: none;
                -moz-user-select: none;
                -webkit-user-select: none;
                user-select: none;
                height: 100%;
                overflow: hidden;
            }

            #controller-container {
                background-color: #ff0000;
                text-align: center;
                font-family: sans-serif;                
                width: 100%;
                height: 100vh;
                position: relative;
            }

            .container_div {
                position: relative;
                display: flex;
                background-color: #ff0000;
                width: calc(100% -10px);
                height: calc(100% -10px);
                padding: 5px;
            }           

            .inner_div{
                display: flex;
                width: 100%;
                justify-content: center;
                align-items: center;
                height: calc(100vh - 10px);
                background-color: green;
            }

            .controls_div {
                padding: 5px;
                display: flex;
                flex-direction: row;
            }

            .button_div {
                width: calc(50% - 5px);
                float: left;
            }

            .right_button{
                float: right;
            }

            .control {
                flex: 1;
                justify-content: center;
                align-items: center;
                height: calc( 100vh - 10px );
                background-color: cadetblue;
                float: left;
            }

            .hidden_initially {
                display: none;
            }

            .btn {
                position: absolute;
                width: 100%;
                height: 100%;
            }

            .btn_left {
                width: 40%;
                left: 2%;
            }

            .btn_right {
                width: 40%;
                right: 2%;
            }

            .center_align {
                text-align: center;
            }
        </style>
    </head>
    <body onload="init()">
        <div id="controller-container">
            <!-- CREATED BY ME -->
            <div id="loading_container_id_div" class="container_div">
                <div class="inner_div">LOADING</div>
            </div>
            <div id="ready_container_id_div" class="container_div view hidden_initially" onmousedown="sendReadyMessage ( 'READY' )">
                <div class="inner_div">TAP TO READY</div>
            </div>
            <div id="done_ready_container_id_div" class="container_div hidden_initially">
                <div class="inner_div">GAME is ABOUT to START</div>
            </div>
            <div id="controls_container_id_div" class="container_div controls_div hidden_initially">
                <div id="jump" class="inner_div button_div" onmousedown="sendMessage ( 'JUMP' )">JUMP</div>
                <div id="dash" class="inner_div button_div right_button" onmousedown="sendMessage ( 'DASH' )">DASH</div>
            </div>
            <div id="waiting_container_id_div" class="container_div hidden_initially" onmousedown="alert ( 'BINGO' )">
                <div class="inner_div">WAITING for Game to END</div>
            </div>
        </div>
        <script>            
            var controlsContainer = document.getElementById ( "controls_container_id_div" );
            var doneReadyContainer = document.getElementById ( "done_ready_container_id_div" );
            var loadingContainer = document.getElementById ( "loading_container_id_div" );
            var readyContainer = document.getElementById ( "ready_container_id_div" );
            var waitingContainer = document.getElementById ( "waiting_container_id_div" );

            function sendReadyMessage ( action ) {                
                airConsole.message ( AirConsole.SCREEN, { "data": { "action": action } } );
            }

            function sendMessage ( action ) {
                airConsole.message ( AirConsole.SCREEN, { "data": { "action": action } } );
            }

            function hideScreens () {
                controlsContainer.style.display = "none";
                doneReadyContainer.style.display = "none";
                loadingContainer.style.display = "none";
                readyContainer.style.display = "none";
                waitingContainer.style.display = "none";
            } 

            function showScreen ( screen ) {
                hideScreens ();
                switch ( screen ) {
                    case "Waiting":
                        waitingContainer.style.display = "block";
                        break;
                    case "Controls":
                        controlsContainer.style.display = "block";
                        break;
                    case "Ready":
                        readyContainer.style.display = "block";
                        break;
                    case "DoneReady":
                        doneReadyContainer.style.display = "block";
                        break;
                    case "PerformEndGame":
                        waitingContainer.style.display = "block";
                        break;
                }
            }
        </script>
    </body>
</html>

When I run it on any device, either Android ( both app and browsers ) or iOS ( browsers ), the part pasted below:

<div id="controls_container_id_div" class="container_div controls_div hidden_initially">
    <div id="jump" class="inner_div button_div" onmousedown="sendMessage ( 'JUMP' )">JUMP</div>
    <div id="dash" class="inner_div button_div right_button" onmousedown="sendMessage ( 'DASH' )">DASH</div>
</div>

SCREENSHOT:

enter image description here

works fine, though the same part is unable to detect "onmousedown" event purely, when played on iOS AirConsole App. It seems like the click events are basically happening in area closer to the center of the screen and the rest of the area is unable to detect any user interaction.

Why is only iOS AirConsole app showing this abnormal behaviour? What can I do in order to make both buttons take click?

Is it some flaw in my CSS or html content. Please do guide me towards the right direction.

This is the game on AirConsole

2

There are 2 best solutions below

0
nIcE cOw On BEST ANSWER

This is the "controller.html" I created, in order to get the click on whole window for iOS AirConsole app

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta content='width=device-width, initial-scale=1, maximum-scale=1 user-scalable=0' name='viewport'>       
        <title>AirConsole Controller</title>
        <link href='https://fonts.googleapis.com/css?family=Play:400,700' rel='stylesheet' type='text/css'>     
        <!-- AirConsole-Controls -->
        <link rel="stylesheet" type="text/css" href="airconsole-controls/button/button.css">
        <link rel="stylesheet" type="text/css" href="airconsole-controls/dpad/dpad.css">
        <!-- Styles -->
        <link rel="stylesheet" type="text/css" href="controller/styles/styles.css">
        <link rel="stylesheet" type="text/css" href="controller/styles/controls.css">
        <!-- AIRCONSOLE -->
        <script type="text/javascript" src="https://www.airconsole.com/api/airconsole-latest.js"></script>
        <script type="text/javascript" src="controller/libs/airconsole_view_manager.js"></script>
        <!-- AIRCONSOLE CONTROLS -->
        <script type="text/javascript" src="airconsole-controls/button/button.js"></script>
        <script type="text/javascript" src="airconsole-controls/dpad/dpad.js"></script>
        <script type="text/javascript" src="airconsole-controls/swipe-analog/swipe-analog.js"></script>
        <script type="text/javascript" src="airconsole-controls/swipe-digital/swipe-digital.js"></script>
        <!-- 3rd Party Libs -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
        <script type="text/javascript" src="controller/libs/handlebars-v4.0.5.js"></script>
        <!-- GENERATOR -->
        <script type="text/javascript" src="controller/js/controller_generator.js"></script>
        <script type="text/javascript" src="controller/js/main.js"></script>        
        <script>
            var airConsole = null;
            var viewManager = null;
            var deviceId = null;
            var characterName = null;            
            /**
              * Sets up the communication to the screen.
              */
            function init() {
                airConsole = new AirConsole ( { orientation: AirConsole.ORIENTATION_LANDSCAPE } );
                airConsole.onMessage = function ( from, data ) {
                    if ( data.action == "REMOVE_LOADING" ) {
                        showScreen ( "Ready" );
                    } else if ( data.action == "SHOW_READY_SCREEN" ) {
                        showScreen ( "Ready" );
                    } else if ( data.action == "READY_RECEIVED" ) {
                        deviceId = data.info.deviceId;
                        characterName = data.info.characterString;
                        var imageId = document.getElementById ( "image_id" );
                        imageId.src = "images/character/" + characterName + ".png";
                        imageId.alt = characterName;                         
                        showScreen ( "DoneReady" );
                    } else if ( data.action == "GAME_STARTED" ) {
                        showScreen ( "Waiting" );
                    } else if ( data.action == "START_GAME" ) {
                        showScreen ( "Controls" );
                    } else if (data.action == "GAME_END") {
                        showScreen ( "PerformEndGame" );
                    } else {
                        alert ( "Message: " + data.info.deviceId );
                    }
                }

                airConsole.onActivePlayersChange = function ( player_number ) {
                    // alert ( "Active Players Change" );
                } 

                airConsole.onReady = function () {
                    // alert ( "On Ready" );
                }

                airConsole.onConnect = function ( id ) {
                    //alert ( "Device ID RECEIVED: " + id );
                }

                airConsole.onGameEnd = function () {
                    alert ( "On Game End" );
                }
            }
        </script>
        <style>
            body{margin:0px;padding:0px;}
            #controller-container {
                background-color: #00ff00;
                text-align: center;
                font-family: sans-serif;                
                width:100%;
                height: 100vh;
                position: relative;
            }

            .image_div {
                pointer-events: none;
                position: absolute;
                z-index:99;
                top:5%;
                width:50vh;
                left: 0;right: 0;margin: 0 auto;
            }
             .image_div img{width: 100%;}

            .bin_div {
                z-index:0;
            }

            .message_div {
                border: 2px outset white;
                background-color: dodgerblue;

            }

            .btn-half {
                text-align: center;
                background-color: green;
                /* background-image: url( "images/background/yellow_square.gif" );*/
                background-size: contain;
                color: #000000;
                display:inline-block;
                width:49%;
                border: 4px solid white;
                height: 98vh;
                z-index: 1;
                position: relative;
            }
        </style>
    </head>
    <body onload="init()">
        <div id="controller-container">
            <!-- REPLACE_HERE START -->
            <div id="view-0" class="view" style="display: flex;">
                <div id="view-0-section-0" class="section" style="height: 100%;">
                    <div id="loading_container_id" class="btn button-element element message_div">
                        <div class="button-text">Loading...</div>
                    </div>
                </div>
            </div>
            <div id="view-3" class="view" style="display: none;">
                <div id="view-3-section-0" class="section" style="height: 100%;">
                    <div id="ready_container_id" class="btn button-element element message_div">
                        <div class="button-text">TAP to READY</div>
                    </div>
                </div>
            </div>
            <div id="view-4" class="view" style="display: none;">
                <div id="view-4-section-0" class="section" style="height: 100%;">
                    <div id="done_ready_container_id" class="btn button-element element message_div">
                        <div class="button-text">Game will Start in few seconds, HOLD ON</div>
                    </div>
                </div>
            </div>
            <div id="view-5" class="view" style="display: none;">
                <div id="view-5-section-0" class="section horizontal" style="height: 100%;position: relative;">
                    <div id="jump_id" class="btn button-element element btn-half btn_div">
                        <div class="button-text">JUMP</div>
                    </div>
                    <div id="dash_id" class="btn button-element element btn-half btn_div">
                        <div class="button-text">DASH</div>
                    </div>
                    <div id="image_container_id" class="btn button-element element image_div">
                        <img id="image_id">
                    </div>
                </div>
            </div>
            <div id="view-6" class="view" style="display: none;">
                <div id="view-6-section-0" class="section" style="height: 100%;">
                    <div id="waiting_container_id" class="btn button-element element message_div">
                        <div class="button-text">Waiting for Game to End...</div>
                    </div>
                </div>
            </div>
            <script type="text/javascript">
                var ctrl_data = '{"orientation":"landscape","selected_view_id":"view-0","views":[{"id":"view-0","sections":[{"id":"view-0-section-0","elements":[{"id":"loading_container_id","key":"button","name":"Button","tmpl":"button","constructor_fn":"ButtonElement","options":{"constructor_args":{},"attr_id":"view-0-section-0-element-0","css_classes":"btn","view_action":{"target":null,"view_id":null},"label":"Loading...","send_onrelease":false,"message_data":[]}}],"classes":[]}]},{"id":"view-3","sections":[{"id":"view-3-section-0","elements":[{"id":"ready_container_id","key":"button","name":"Button","tmpl":"button","constructor_fn":"ButtonElement","options":{"constructor_args":{},"attr_id":"view-3-section-0-element-0","css_classes":"btn","view_action":{"target":null,"view_id":null},"label":"TAP to READY","send_onrelease":false,"message_data":[{"key":"action","value":"READY"}]}}],"classes":[]}]},{"id":"view-4","sections":[{"id":"view-4-section-0","elements":[{"id":"done_ready_container_id","key":"button","name":"Button","tmpl":"button","constructor_fn":"ButtonElement","options":{"constructor_args":{},"attr_id":"view-4-section-0-element-0","css_classes":"btn","view_action":{"target":null,"view_id":null},"label":"Game will Start in few seconds, HOLD ON","send_onrelease":false,"message_data":[]}}],"classes":[]}]},{"id":"view-5","sections":[{"id":"view-5-section-0","elements":[{"id":"jump_id","key":"button","name":"Button","tmpl":"button","constructor_fn":"ButtonElement","options":{"constructor_args":{},"attr_id":"view-5-section-0-element-0","css_classes":"btn","view_action":{"target":null,"view_id":null},"label":"JUMP","send_onrelease":false,"message_data":[{"key":"action","value":"JUMP"}]}},{"id":"dash_id","key":"button","name":"Button","tmpl":"button","constructor_fn":"ButtonElement","options":{"constructor_args":{},"attr_id":"view-5-section-0-element-1","css_classes":"btn","view_action":{"target":null,"view_id":null},"label":"DASH","send_onrelease":false,"message_data":[{"key":"action","value":"DASH"}]}}],"classes":["horizontal"]}]},{"id":"view-6","sections":[{"id":"view-6-section-0","elements":[{"id":"waiting_container_id","key":"button","name":"Button","tmpl":"button","constructor_fn":"ButtonElement","options":{"constructor_args":{},"attr_id":"view-6-section-0-element-0","css_classes":"btn","view_action":{"target":null,"view_id":null},"label":"Waiting for Game to End...","send_onrelease":false,"message_data":[]}}],"classes":[]}]}]}';
            </script>
            <!-- REPLACE_HERE END -->
        </div>      
        <script>
            var controlsContainer = document.getElementById ( "view-5" );
            var doneReadyContainer = document.getElementById ( "view-4" );
            var loadingContainer = document.getElementById ( "view-0" );
            var readyContainer = document.getElementById ( "view-3" );
            var waitingContainer = document.getElementById ( "view-6" );

            function sendReadyMessage ( action ) {                
                airConsole.message ( AirConsole.SCREEN, { "data": { "action": action } } );
            }

            function sendMessage ( action ) {
                airConsole.message ( AirConsole.SCREEN, { "data": { "action": action } } );
            }

            function hideScreens () {
                controlsContainer.style.display = "none";
                doneReadyContainer.style.display = "none";
                loadingContainer.style.display = "none";
                readyContainer.style.display = "none";
                waitingContainer.style.display = "none";
            } 

            function showScreen ( screen ) {
                hideScreens ();
                switch ( screen ) {
                    case "Waiting":
                        waitingContainer.style.display = "flex";
                        break;
                    case "Controls":
                        controlsContainer.style.display = "flex";
                        break;
                    case "Ready":
                        readyContainer.style.display = "flex";
                        break;
                    case "DoneReady":
                        doneReadyContainer.style.display = "flex";
                        break;
                    case "PerformEndGame":
                        waitingContainer.style.display = "flex";
                        break;
                }
            }
        </script>
    </body>
</html>

A little help in generating the html with AirConsole Controller Generator, did the trick and personal css manipulation helped in achieving the desired output.

1
Lumion On

I don't have an iOS phone to test this, but from what I can tell it seems pretty odd that you use

.inner_div {
    width: 100%;
}

... where .inner_div is used for both "Jump" and "Dash" buttons, but you also use

.button_div {
    width: calc(50% - 5px);
    float: left;
}

So why do you have two different width values for same DIV elements?

Also, I would maybe do this little bit differently to reduce the amount of code and make things simpler. If you're interested I can give an example.

However, I hope this helps you out a little bit.