Is there a way to check the game is running in a mobile or desktop browser. I am working on a platformer game and I need to show on-screen controls if that game is running in mobile browsers.
Yes!
thanks, i checked sys info “system_name” parameter returns “HTML5” for both mobile and desktop browsers. is there any other flag i need to check to detect the game is running on mobile browsers ?
Have you checked “sys.get_sys_info().user_agent” ?
1 Like
just checked user_agent, I think it has enough data to detect mobile browsers. Thanks, Mathias, totebo.
1 Like
(I am writing in this thread as it is easily searchable)
I ported the device.js module to Lua and we use it in our games to detect the platform on which the HTML5 game is running. The module uses sys.get_sys_info().user_agent
to identify the device type mobile
, tablet
, desktop
and some other data.
Usage:
local device = require("device")
if device.type == "mobile" then
-- do something!
end
-- Access these properties on the device object:
-- device.type: 'mobile', 'tablet', 'desktop', or 'unknown'
-- device.orientation: 'landscape', 'portrait', or 'unknown'
-- device.os: 'ios', 'iphone', 'ipad', 'ipod', 'android', 'blackberry', 'windows', 'macos', 'fxos', 'meego', 'television', or 'unknown'
-- Plus the module is able to detect the current screen orientation
-- in its own way and for this you can set a listener
-- via device.on_change_orientation and call device.handle_orientation()
-- via timer.delay.
device.on_change_orientation(function(new_orientation)
print("New orientation", new_orientation)
end)
timer.delay(1, true, device.handle_orientation)
21 Likes