Namespace: device

me. device

A singleton object representing the device capabilities and specific events
Source:
device.js, line 8

Members

<static, readonly> accelerationX :Number

contains the g-force acceleration along the x-axis.
Type:
  • Number
Source:
device.js, line 432

<static, readonly> accelerationY :Number

contains the g-force acceleration along the y-axis.
Type:
  • Number
Source:
device.js, line 442

<static, readonly> accelerationZ :Number

contains the g-force acceleration along the z-axis.
Type:
  • Number
Source:
device.js, line 452

<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.
Type:
  • Number
Source:
device.js, line 482

<static, readonly> android :Boolean

equals to true if the device is an Android platform.
Type:
  • Boolean
Source:
device.js, line 358

<static, readonly> android2 :Boolean

equals to true if the device is an Android 2.x platform.
Type:
  • Boolean
Source:
device.js, line 367

<static, readonly> beta :Number

Device orientation Beta property. Gives angle on tilting a portrait held phone forward or backward
Type:
  • Number
Source:
device.js, line 472

<static, readonly> BlackBerry :Boolean

equals to true if the device is a BlackBerry platform.
Type:
  • Boolean
Source:
device.js, line 414

<static, readonly> chromeOS :Boolean

equals to true if the device is running on ChromeOS.
Type:
  • Boolean
Source:
device.js, line 396

<static, readonly> cocoon :Boolean

equals to true if the game is running under cocoon/cocoonJS.
Type:
  • Boolean
Source:
device.js, line 386
See:

<static, readonly> ejecta :Boolean

equals to true if the game is running under Ejecta.
Type:
  • Boolean
Source:
device.js, line 376
See:

<static, readonly> gamma :Number

Device orientation Gamma property. Gives angle on tilting a portrait held phone left or right
Type:
  • Number
Source:
device.js, line 462

<static, readonly> hasAccelerometer :Boolean

Browser accelerometer capabilities
Type:
  • Boolean
Source:
device.js, line 263

<static, readonly> hasDeviceOrientation :Boolean

Browser device orientation
Type:
  • Boolean
Source:
device.js, line 272

<static, readonly> hasFullscreenSupport :Boolean

Browser full screen support
Type:
  • Boolean
Source:
device.js, line 281

<static, readonly> hasPointerLockSupport :Boolean

Browser pointerlock api support
Type:
  • Boolean
Source:
device.js, line 290

<static, readonly> iOS :Boolean

equals to true if the device is an iOS platform.
Type:
  • Boolean
Source:
device.js, line 349

<static, readonly> isFullscreen :Boolean

Returns true if the browser/device is in full screen mode.
Type:
  • Boolean
Source:
device.js, line 976

<static, readonly> isMobile :Boolean

equals to true if a mobile device
(Android | iPhone | iPad | iPod | BlackBerry | Windows Phone | Kindle)
Type:
  • Boolean
Source:
device.js, line 339

<static, readonly> Kindle :Boolean

equals to true if the device is a Kindle platform.
Type:
  • Boolean
Source:
device.js, line 423

<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)
Type:
  • String
Source:
device.js, line 493
See:

<static, readonly> localStorage :Boolean

Browser Local Storage capabilities
(this flag will be set to false if cookies are blocked)
Type:
  • Boolean
Source:
device.js, line 253

<static, readonly> maxTouchPoints :Number

Return the maximum number of simultaneous touch contact points are supported by the current device.
Type:
  • Number
Source:
device.js, line 308
Example
if (me.device.maxTouchPoints > 1) {
    // device supports multi-touch
}

<static, readonly> nativeBase64 :Boolean

Browser Base64 decoding capability
Type:
  • Boolean
Source:
device.js, line 299

<static, readonly> sound :Boolean

Returns true if the browser/device has audio capabilities.
Type:
  • Boolean
Source:
device.js, line 999

<static, readonly> touch :Boolean

Touch capabilities
Type:
  • Boolean
Source:
device.js, line 321

<static, readonly> ua :String

the `ua` read-only property returns the user agent string for the current browser.
Type:
  • String
Source:
device.js, line 244

<static, readonly> wheel :Boolean

W3C standard wheel events
Type:
  • Boolean
Source:
device.js, line 330

<static, readonly> wp :Boolean

equals to true if the device is a Windows Phone platform.
Type:
  • Boolean
Source:
device.js, line 405

Methods

<static> enableSwipe(enable)

enable/disable swipe on WebView.
Parameters:
Name Type Argument Default Description
enable boolean <optional>
true enable or disable swipe.
Source:
device.js, line 580

<static> exitFullscreen()

Exit fullscreen mode. Requires fullscreen support from the browser/device.
Source:
device.js, line 629

<static> getPixelRatio()

return the device pixel ratio
Source:
device.js, line 641

<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"
Source:
device.js, line 663
See:
Returns:
the screen orientation
Type
String

<static> getStorage(type)

return the device storage
Parameters:
Name Type Argument Default Description
type String <optional>
"local"
Source:
device.js, line 757
Returns:
me.save object

<static> isLandscape() → {Boolean}

return true if the device screen orientation is in Portrait mode
Source:
device.js, line 746
Returns:
Type
Boolean

<static> isPortrait() → {Boolean}

return true if the device screen orientation is in Portrait mode
Source:
device.js, line 735
Returns:
Type
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.
Source:
device.js, line 699
See:
Returns:
true if the orientation was unsuccessfully locked
Type
Boolean

<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
Source:
device.js, line 505
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(element)

Triggers a fullscreen request. Requires fullscreen support from the browser/device.
Parameters:
Name Type Argument Default Description
element Object <optional>
default canvas object the element to be set in full-screen mode.
Source:
device.js, line 599
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
Source:
device.js, line 848

<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.
Source:
device.js, line 805
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.
Source:
device.js, line 717
See:
Returns:
true if the orientation was unsuccessfully unlocked
Type
Boolean

<static> unwatchAccelerometer()

unwatch Accelerometor event
Source:
device.js, line 894

<static> unwatchDeviceOrientation()

unwatch Device orientation event
Source:
device.js, line 932

<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
Source:
device.js, line 946
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
Source:
device.js, line 860
Returns:
false if not supported by the device
Type
Boolean

<static> watchDeviceOrientation() → {Boolean}

watch the device orientation event
Source:
device.js, line 916
Returns:
false if not supported by the device
Type
Boolean