Detecting mobile devices

22 January 2018 20:34
Hello everybody
(second question but I'm still a beginner)

I try the tutorial "Making a game p4: Mobile Device" but I have problems

I add the "detect mobile" function to the "// Place your code here" section of Project.js

I change the "init function" as described in the tutorial and change the canvas id to my (main_canvas_container) canvas id

If I want to run the project, I only get a black screen

where is the problem, what am I doing wrong?

test project is attached

thank you for your help!
24 January 2018 14:19
You've attached a deployed version of your project, which means that sources are compiled and obfuscated. Could you attach the sources?
Alexander (Blend4Web Team)
24 January 2018 15:03
Hello, now I have attached the folder with the source.

Thank you for your help!
24 January 2018 19:05

diff -rupN mobile1/mobile.html mobile/mobile.html
— mobile1/mobile.html 2018-01-22 19:26:03.000000000 +0300
+++ mobile/mobile.html 2018-01-24 18:55:52.418911910 +0300
@@ -10,7 +10,7 @@

<link rel="stylesheet" href="mobile.css" type="text/css">

-<script type="text/javascript" src="..\..\dist\b4w.js"></script>
+<script type="text/javascript" src="../../dist/b4w.js"></script>

<script type="text/javascript" src="mobile.js"></script>

diff -rupN mobile1/mobile.js mobile/mobile.js
— mobile1/mobile.js 2018-01-22 20:04:36.000000000 +0300
+++ mobile/mobile.js 2018-01-24 18:58:05.990914070 +0300
@@ -9,6 +9,7 @@ var m_cfg = require("config");
var m_data = require("data");
var m_preloader = require("preloader");
var m_ver = require("version");
+var m_main = require("main");

// detect application mode
var DEBUG = (m_ver.type() == "DEBUG");
@@ -23,7 +24,7 @@ var APP_ASSETS_PATH = m_cfg.get_assets_p

exports.init = function() {

- if(detect_mobile())
+ if(m_main.detect_mobile())
var quality = m_cfg.P_LOW;
var quality = m_cfg.P_HIGH;

detect_mobile should be called from main module.
And I also changed the path to the b4w.js: src="../../dist/b4w.js" . It seems that the path is generated incorrectly on your system. Are you using Windows?
Alexander (Blend4Web Team)
24 January 2018 19:21
Hello Alexander, yes I use Windows 10
24 January 2018 20:16
hmm this is crazy, see the attached screenshot I would never have noticed.

I also changed the * .js as described by you. now it's working

Thanks a lot and keep up the good work! Thank you
25 January 2018 10:39
On the last screenshot you have many js included in html, it seems that this project is not updated for 17.12. Use "check modules" and then "update modules" to update it to 17.12. All this script tags will be replaced by the one with src="../../dist/b4w.js". Anyway the first thing you should do when meeting issues is to look at the browser console(F12 in most browsers).
We will fix the bug you found.
Alexander (Blend4Web Team)
Please register or log in to leave a reply.