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.

static, readonly accelerationY :Number

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

static, readonly accelerationZ :Number

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

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.

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

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

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 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 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 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 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}

watch Accelerator event

Returns:
Boolean -

false if not supported by the device

static watchDeviceOrientation() → {Boolean}

watch the device orientation event

Returns:
Boolean -

false if not supported by the device