me.device

A singleton object representing the device capabilities and specific events

Members

static, readonly accelerationX :Number

contains the g-force acceleration along the x-axis.

See:

static, readonly accelerationY :Number

contains the g-force acceleration along the y-axis.

See:

static, readonly accelerationZ :Number

contains the g-force acceleration along the z-axis.

See:

static, readonly alpha :Number

Device orientation Alpha property. Gives angle based on the rotation of the phone around its z axis. The z-axis is perpendicular to the phone, facing out from the center of the screen.

See:

static, readonly android :Boolean

equals to true if the device is an Android platform.

static, readonly android2 :Boolean

equals to true if the device is an Android 2.x platform.

static, readonly beta :Number

Device orientation Beta property. Gives angle on tilting a portrait held phone forward or backward

See:

static, readonly BlackBerry :Boolean

equals to true if the device is a BlackBerry platform.

static, readonly chromeOS :Boolean

equals to true if the device is running on ChromeOS.

static, readonly devicePixelRatio :Number

Ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device.

static, readonly ejecta :Boolean

equals to true if the game is running under Ejecta.

See:

static, readonly gamma :Number

Device orientation Gamma property. Gives angle on tilting a portrait held phone left or right

See:

static, readonly hasAccelerometer :Boolean

Browser accelerometer capabilities

static, readonly hasDeviceOrientation :Boolean

Browser device orientation

static, readonly hasFullscreenSupport :Boolean

Browser full screen support

static, readonly hasPointerLockSupport :Boolean

Browser pointerlock api support

static, readonly hasWebAudio :Boolean

Device WebAudio Support

static, readonly iOS :Boolean

equals to true if the device is an iOS platform.

static, readonly isFullscreen :Boolean

Returns true if the browser/device is in full screen mode.

static, readonly isMobile :Boolean

equals to true if a mobile device
(Android | iPhone | iPad | iPod | BlackBerry | Windows Phone | Kindle)

static, readonly isWeixin :Boolean

equals to true if the game is running under Wechat.

static, readonly Kindle :Boolean

equals to true if the device is a Kindle platform.

static, readonly language :String

a string representing the preferred language of the user, usually the language of the browser UI. (will default to "en" if the information is not available)

See:

static, readonly linux :Boolean

equals to true if the device is a Linux platform.

static, readonly localStorage :Boolean

Browser Local Storage capabilities
(this flag will be set to false if cookies are blocked)

static, readonly maxTouchPoints :Number

Return the maximum number of simultaneous touch contact points are supported by the current device.

Example
if (me.device.maxTouchPoints > 1) {
    // device supports multi-touch
}

static, readonly nativeBase64 :Boolean

Browser Base64 decoding capability

static, readonly OffScreenCanvas :Boolean

equals to true if the device browser supports OffScreenCanvas.

static, readonly sound :Boolean

Returns true if the browser/device has audio capabilities.

static, readonly touch :Boolean

Touch capabilities

static, readonly ua :String

the ua read-only property returns the user agent string for the current browser.

static, readonly wheel :Boolean

W3C standard wheel events

static, readonly wp :Boolean

equals to true if the device is a Windows Phone platform.

Methods

static enableSwipe(enableopt)

enable/disable swipe on WebView.

Parameters:
Name Type Attributes Default Description
enable boolean <optional>
true

enable or disable swipe.

static exitFullscreen()

Exit fullscreen mode. Requires fullscreen support from the browser/device.

static focus()

Makes a request to bring this device window to the front.

Example
if (clicked) {
   me.device.focus();
 }

static getElement(element) → {HTMLElement}

return the DOM element for the given element name or HTMLElement object

Parameters:
Name Type Description
element String | HTMLElement

the parent element name or a HTMLElement object

Returns:
HTMLElement -

the corresponding DOM Element or null if not existing

static getElementBounds(element) → {DOMRect}

returns the size of the given HTMLElement and its position relative to the viewport

Parameters:
Name Type Description
element String | HTMLElement

an HTMLElement object

Returns:
DOMRect -

the size and position of the element relatively to the viewport

See:

static getMaxShaderPrecision(gl) → {Boolean}

return the highest precision format supported by this device for GL Shaders

Parameters:
Name Type Description
gl WebGLRenderingContext
Returns:
Boolean -

"lowp", "mediump", or "highp"

static getParentBounds(element) → {DOMRect}

returns the size of the given HTMLElement Parent and its position relative to the viewport

Parameters:
Name Type Description
element String | HTMLElement

an HTMLElement object

Returns:
DOMRect -

the size and position of the given element parent relative to the viewport

See:

static getParentElement(element) → {HTMLElement}

return the parent DOM element for the given parent name or HTMLElement object

Parameters:
Name Type Description
element String | HTMLElement

the parent element name or a HTMLElement object

Returns:
HTMLElement -

the parent Element

static getPixelRatio()

Deprecated:
  • since 5.1.0
See:

static getScreenOrientation() → {String}

Return a string representing the orientation of the device screen. It can be "any", "natural", "landscape", "portrait", "portrait-primary", "portrait-secondary", "landscape-primary", "landscape-secondary"

Returns:
String -

the screen orientation

See:

static getStorage(typeopt)

return the device storage

Parameters:
Name Type Attributes Default Description
type String <optional>
"local"
Returns:
-

me.save object

static isLandscape() → {Boolean}

return true if the device screen orientation is in Portrait mode

Returns:
Boolean

static isPortrait() → {Boolean}

return true if the device screen orientation is in Portrait mode

Returns:
Boolean

static isWebGLSupported(optionsopt) → {Boolean}

returns true if the device supports WebGL

Parameters:
Name Type Attributes Description
options Object <optional>

context creation options

Properties
Name Type Attributes Default Description
failIfMajorPerformanceCaveat Boolean <optional>
true

If true, the renderer will switch to CANVAS mode if the performances of a WebGL context would be dramatically lower than that of a native application making equivalent OpenGL calls.

Returns:
Boolean -

true if WebGL is supported

static lockOrientation() → {Boolean}

locks the device screen into the specified orientation.
This method only works for installed Web apps or for Web pages in full-screen mode.

Returns:
Boolean -

true if the orientation was unsuccessfully locked

See:

static onReady(fn)

specify a function to execute when the Device is fully loaded and ready

Parameters:
Name Type Description
fn function

the function to be executed

Example
// small game skeleton
var game = {
   // called by the me.device.onReady function
   onload : function () {
      // init video
      if (!me.video.init('screen', 640, 480, true)) {
         alert("Sorry but your browser does not support html 5 canvas.");
         return;
      }

      // initialize the "audio"
      me.audio.init("mp3,ogg");

      // set callback for ressources loaded event
      me.loader.onload = this.loaded.bind(this);

      // set all ressources to be loaded
      me.loader.preload(game.assets);

      // load everything & display a loading screen
      me.state.change(me.state.LOADING);
   },

   // callback when everything is loaded
   loaded : function () {
      // define stuff
      // ....

      // change to the menu screen
      me.state.change(me.state.PLAY);
   }
}; // game

// "bootstrap"
me.device.onReady(function () {
   game.onload();
});

static requestFullscreen(elementopt)

Triggers a fullscreen request. Requires fullscreen support from the browser/device.

Parameters:
Name Type Attributes Default Description
element Object <optional>
default canvas object

the element to be set in full-screen mode.

Example
// add a keyboard shortcut to toggle Fullscreen mode on/off
me.input.bindKey(me.input.KEY.F, "toggleFullscreen");
me.event.subscribe(me.event.KEYDOWN, function (action, keyCode, edge) {
   // toggle fullscreen on/off
   if (action === "toggleFullscreen") {
      if (!me.device.isFullscreen) {
         me.device.requestFullscreen();
      } else {
         me.device.exitFullscreen();
      }
   }
});

static turnOffPointerLock()

Exits pointer lock. Works on supported devices & browsers

static turnOnPointerLock()

Enters pointer lock, requesting it from the user first. Works on supported devices & browsers Must be called in a click event or an event that requires user interaction. If you need to run handle events for errors or change of the pointer lock, see below.

Example
document.addEventListener("pointerlockchange", pointerlockchange, false);
document.addEventListener("mozpointerlockchange", pointerlockchange, false);
document.addEventListener("webkitpointerlockchange", pointerlockchange, false);

document.addEventListener("pointerlockerror", pointerlockerror, false);
document.addEventListener("mozpointerlockerror", pointerlockerror, false);
document.addEventListener("webkitpointerlockerror", pointerlockerror, false);

static unlockOrientation() → {Boolean}

unlocks the device screen into the specified orientation.
This method only works for installed Web apps or for Web pages in full-screen mode.

Returns:
Boolean -

true if the orientation was unsuccessfully unlocked

See:

static unwatchAccelerometer()

unwatch Accelerometor event

static unwatchDeviceOrientation()

unwatch Device orientation event

static vibrate(pattern)

the vibrate method pulses the vibration hardware on the device,
If the device doesn't support vibration, this method has no effect.
If a vibration pattern is already in progress when this method is called, the previous pattern is halted and the new one begins instead.

Parameters:
Name Type Description
pattern Number | Array.<Number>

pattern of vibration and pause intervals

Example
// vibrate for 1000 ms
me.device.vibrate(1000);
// or alternatively
me.device.vibrate([1000]);
// vibrate for 50 ms, be still for 100 ms, and then vibrate for 150 ms:
me.device.vibrate([50, 100, 150]);
// cancel any existing vibrations
me.device.vibrate(0);

static watchAccelerometer() → {Boolean}

Enable monitor of the device accelerator to detect the amount of physical force of acceleration the device is receiving. (one some device a first user gesture will be required before calling this function)

Returns:
Boolean -

false if not supported or permission not granted by the user

See:
Example
// try to enable device accelerometer event on user gesture
me.input.registerPointerEvent("pointerleave", me.game.viewport, function() {
    if (me.device.watchAccelerometer() === true) {
        // Success
        me.input.releasePointerEvent("pointerleave", me.game.viewport);
    } else {
        // ... fail at enabling the device accelerometer event
    }
});

static watchDeviceOrientation() → {Boolean}

Enable monitor of the device orientation to detect the current orientation of the device as compared to the Earth coordinate frame. (one some device a first user gesture will be required before calling this function)

Returns:
Boolean -

false if not supported or permission not granted by the user

See:
Example
// try to enable device orientation event on user gesture
me.input.registerPointerEvent("pointerleave", me.game.viewport, function() {
    if (me.device.watchDeviceOrientation() === true) {
        // Success
        me.input.releasePointerEvent("pointerleave", me.game.viewport);
    } else {
        // ... fail at enabling the device orientation event
    }
});