Full webpage experience

Hello.

I’m currently working on a web game, which should be playable in browsers both mobile and desktop. When building web-mobile from Cocos Creator I get the following problems achieving full screen(landscape on mobile devices).

  • Browsers work fine.
  • Android: Usually one can touch/tab on a canvas to make it full screen. This does not work, but removing the <div id="GameDiv" class="wrapper"> will fix this.
  • iOS: This is a general iOS problem, where people want to go into what is called “minimal view”. A solution can be to use brim.js. So this is where I get problems. When I wrap the canvas in <div>'s from brim.js. The size of the canvas in browsers shrinks and wont take touch/click inputs. The same happens on android.
    And It does not fix the problem on iOS. Here the canvas float down in the bottom left corner. But forcing the minimal view to go away and removing it again will make the game go full screen.

All this is done without editing the main.js file:

    var option = {
        //width: width,
        //height: height,
        id: 'GameCanvas',
        scenes: _CCSettings.scenes,
        debugMode: _CCSettings.debug ? cc.DebugMode.INFO : cc.DebugMode.ERROR,
        showFPS: _CCSettings.debug,
        frameRate: 60,
        jsList: [
            _CCSettings.debug ? 'src/project.dev.js' : 'src/project.js'
        ]
    };

I can set the height and width here in the options to fix how the game looks in a browser, but the click event does still not work and the canvas won’t resize with the browser. Also, it does not seems like the cocos code uses the id for anything, changing this will resolve in an cocos error cause it is looking for ‘GameCanvas’.

My index.html looks like this:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">

  <title>Cocos Creator | Orbs</title>

  <!--http://www.html5rocks.com/en/mobile/mobifying/-->
  <meta name="viewport"
        content="width=device-width,user-scalable=no,initial-scale=1, minimum-scale=1,maximum-scale=1,target-densitydpi=device-dpi"/>


  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="format-detection" content="telephone=no">

  <meta name="full-screen" content="yes"/>
  <meta name="screen-orientation" content=""/>
  <meta name="x5-orientation" content="">
  <meta name="browsermode" content="application">
  <meta name="x5-page-mode" content="app">
  <meta name="msapplication-tap-highlight" content="no">
  <meta name="x5-fullscreen" content="true"/>
  <meta name="360-fullscreen" content="true"/>

  <!--<link rel="apple-touch-icon" href=".png" />-->
  <!--<link rel="apple-touch-icon-precomposed" href=".png" />-->
  <link href="style.css" rel="stylesheet">

  <script src="brim.js" charset="utf-8"></script>
  <script src="scream.js" charset="utf-8"></script>
  <script src="platform.js" charset="utf-8"></script>
</head>
<body>

<div id="brim-main">
  <canvas id="GameCanvas" oncontextmenu="event.preventDefault()" tabindex="0"></canvas>
  <div id="splash">
    <div class="progress-bar stripes">
      <span style="width: 0%"></span>
    </div>
  </div>
</div>

<div id="brim-mask">
  <p>Scroll down to go fullscreen or rotate device</p>
</div>

<script>
  var scream, brim;

  if (platform.os.family == 'iOS' && parseInt(platform.os.version, 10) > 8 || platform.ua.indexOf('like Mac OS X') != -1) {
    scream = gajus.Scream({
      width: {
        portrait: 320,
        landscape: 568
      }
    });

    brim = gajus.Brim({
      viewport: scream
    });

    brim.on('viewchange', function (e) {
      document.body.className = e.viewName;

      if(e.viewName == "minimal") {
        // Show game canvas
      }
    });
  } else {
    // Show game canvas
    document.querySelector('#brim-main').style.display = 'block';
  }
</script>
<script src="src/settings.js" charset="utf-8"></script>
<script src="cocos2d-js-min.js" charset="utf-8"></script>
<script src="src/project.js" charset="utf-8"></script>
<script src="main.js" charset="utf-8"></script>

 </body>
</html>

Does anyone know how to do stuff like this ? Or any hints about handling the canvas re-sizing.

Martin

Thanks a lot for your feedback! We’ll look into this.

I need more info of your Android platform to reproduce the issue:

  • Android system version
  • Brand and product name of the phone
  • Which browser?

Hi,

I’m using a Sony Xperia Z3 compact running android v. 5.1.1 and using Chrome.

The current status is that I think the problem is caused by brim.js, and how it resize elements when rotating the display. Next step is to test if it also happens when using a basic canvas (no Cocos).

Just wondering, did you ever get this to work properly?

I too am also developing a game for web mobile in landscape mode, and the fact that the url bar and the navigation bar in iOS would sometimes crop in and occupy some of the canvas space is annoying and even deal-breaking. On the other hand Chrome on Android would allow my game to go into “minimal view” but only after my game has loaded so things like my canvas size that I need predetermined would change with undesirable effects. Currently looking for a solution for this problem too.

Hello, did you get result you wanted?

I faced a problem, that fullscreen game run MUCH slower, than its usual-screen version(which is absolutely perfect).

Does anybody else run into the same problem?

I haven’t run into the problem you described.

Due to constraints set by the browser I gave up on trying to force my game to go full screen. Because things like iOS Safari’s url bar will crop up in landscape when you tap certain areas on the screen and there is no way to prevent such behaviors.

Instead I just readjust my frame/canvas size on the window onResize event, because this event gets triggered every time things like the url bar or navigation crops in and impacts the visible area of my game.

I can post my code on how to do this if you like, but it sounds like you’re chasing a different issue here.

Thanks for your reply! After a lot of investigation and optimizations, I forced my app to run perfect on iOS in both, usual and fullscreen mode. I have always 60fps. But I have 10fps maximum in chrome browser on Android with Galaxy Edge 7! That’s just crazy. Standard Internet browser on Android runs at maximum 20fps(!?). So, now I’m looking how to made a game run on Android smoothly… Have you ever faced such a slowdown on Android? I’m asking here, because nobody answers on my other posts :slight_smile:

Hi @crauss,
How you forced your app for fullscreen mode on ios safari browser. Actually, I am stuck on the same so can you share your code.

@mbu did you ever solve this with Cocos Creator? I’m trying to figure it out at the moment.

Thanks!

@Ronsku Which problem you are facing with Cocos Creator?

Just trying to get fullscreen to work with my game for Safari mobile browsers in new IOS versions. Did you ever get this to work with the swipe motion?

I also tried the same, but didn’t achieve fullscreen mode for Safari mobile browser as mobile safari browser does not allow us to do that from our end. So i managed the things with ‘onResize’ function of Window.