device

namespace device

boolean

device type and capabilities

Public Properties


accelerationX device.js:297
accelerationX: number = 0

number

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

See: device.watchAccelerometer
accelerationY device.js:308
accelerationY: number = 0

number

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

See: device.watchAccelerometer
accelerationZ device.js:319
accelerationZ: number = 0

number

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

See: device.watchAccelerometer
alpha device.js:352
alpha: number = 0

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: device.watchDeviceOrientation
autoFocus device.js:401
autoFocus: boolean = true

boolean

Specify whether to automatically bring the window to the front

beta device.js:341
beta: number = 0

number

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

See: device.watchDeviceOrientation
devicePixelRatio device.js:276
devicePixelRatio: number

number

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

gamma device.js:330
gamma: number = 0

number

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

See: device.watchDeviceOrientation
hasAccelerometer device.js:167
hasAccelerometer: boolean = --

boolean

Browser accelerometer capabilities

hasDeviceOrientation device.js:146
hasDeviceOrientation: boolean = --

boolean

Browser device orientation

hasFullscreenSupport device.js:177
hasFullscreenSupport: boolean

boolean

Browser full screen support

hasHTML5Audio device.js:201
hasHTML5Audio: boolean

boolean

Device HTML5Audio Support

hasPointerLockSupport device.js:136
hasPointerLockSupport: boolean

boolean

Browser pointerlock api support

hasVideo device.js:222
hasVideo: boolean

boolean

Device Video Support

hasWebAudio device.js:191
hasWebAudio: boolean = --

boolean

Device WebAudio Support

isMobile device.js:286
isMobile: boolean

boolean

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

language device.js:264
language: string

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: http://www.w3schools.com/tags/ref_language_codes.asp
localStorage device.js:233
localStorage: boolean

boolean

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

maxTouchPoints device.js:111
maxTouchPoints: number

number

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

if (me.device.maxTouchPoints > 1) {
    // device supports multi-touch
}
nativeBase64 device.js:254
nativeBase64: boolean

boolean

Browser Base64 decoding capability

offscreenCanvas device.js:244
offscreenCanvas: boolean

boolean

equals to true if the device browser supports OffScreenCanvas.

pauseOnBlur device.js:364
pauseOnBlur: boolean = true

boolean
Deprecated: since 15.4.0

Specify whether to pause the game when losing focus

See: Application.pauseOnBlur
platform device.js:71
platform: device.platform

device.platform

the device platform type

pointerEvent device.js:91
pointerEvent: boolean = --

boolean

True if the browser supports Pointer Events

resumeOnFocus device.js:376
resumeOnFocus: boolean = true

boolean
Deprecated: since 15.4.0

Specify whether to unpause the game when gaining focus

See: Application.resumeOnFocus
screenOrientation device.js:156
screenOrientation: boolean

boolean

Supports the ScreenOrientation API

See: https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/onchange
sound device.js:211
sound: boolean

boolean

Returns true if the browser/device has audio capabilities.

stopOnBlur device.js:388
stopOnBlur: boolean = false

boolean
Deprecated: since 15.4.0

Specify whether to stop the game when losing focus or not. The engine restarts on focus if this is enabled.

See: Application.stopOnBlur
touch device.js:101
touch: boolean

boolean

Touch capabilities (support either Touch or Pointer events)

touchEvent device.js:81
touchEvent: boolean = --

boolean

True if the browser supports Touch Events

wheel device.js:125
wheel: boolean

boolean

W3C standard wheel events

Public Methods


enableSwipe device.js:492
enableSwipe(enable: boolean) → {}

enable/disable swipe on WebView.

Parameters:
Name Type Attributes Default Description
enable boolean

<optional>

true

enable or disable swipe.

exitFullscreen device.js:553
exitFullscreen() → {}

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

focus device.js:788
focus() → {}

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

if (clicked) {
  me.device.focus();
}
getElement device.js:701
getElement(element: string | HTMLElement) → {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:
Type Description
HTMLElement

the corresponding DOM Element or null if not existing

getElementBounds device.js:729
getElementBounds(element: string | HTMLElement) → {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:
Type Description
DOMRect

the size and position of the element relatively to the viewport

See: https://developer.mozilla.org/en-US/docs/Web/API/DOMRect
getParentBounds device.js:749
getParentBounds(element: string | HTMLElement) → {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:
Type Description
DOMRect

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

See: https://developer.mozilla.org/en-US/docs/Web/API/DOMRect
getParentElement device.js:683
getParentElement(element: string | HTMLElement) → {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:
Type Description
HTMLElement

the parent Element

getScreenOrientation device.js:565
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:
Type Description
string

the screen orientation

See: https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation
getStorage device.js:664
getStorage(type: string) → {object}

return the device storage

Parameters:
Name Type Attributes Default Description
type string

<optional>

"local"
Returns:
Type Description
object

a reference to the device storage

See: save
isFullscreen device.js:512
isFullscreen() → {boolean}

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

Returns:
Type Description
boolean
isLandscape device.js:653
isLandscape() → {boolean}

return true if the device screen orientation is in Portrait mode

Returns:
Type Description
boolean
isPortrait device.js:642
isPortrait() → {boolean}

return true if the device screen orientation is in Portrait mode

Returns:
Type Description
boolean
isWebGLSupported device.js:763
isWebGLSupported(options: object) → {boolean}

returns true if the device supports WebGL

Parameters:
Name Type Attributes Default Description
options object

<optional>

context creation options

options.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:
Type Description
boolean

true if WebGL is supported

lockOrientation device.js:601
lockOrientation(orientation: string | Array<string>) → {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.

Parameters:
Name Type Description
orientation string | Array<string>

The orientation into which to lock the screen.

Returns:
Type Description
boolean

true if the orientation was unsuccessfully locked

See: https://developer.mozilla.org/en-US/docs/Web/API/Screen/lockOrientation
onReady device.js:411
onReady(fn: Function) → {}

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

 // small game skeleton
 let 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();
 });
Parameters:
Name Type Description
fn Function

the function to be executed

requestFullscreen device.js:527
requestFullscreen(element: Element) → {}

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

// add a keyboard shortcut to toggle Fullscreen mode on/off
me.input.bindKey(me.input.KEY.F, "toggleFullscreen");
me.event.on(me.event.KEYDOWN, function (action, keyCode, edge) {
   // toggle fullscreen on/off
   if (action === "toggleFullscreen") {
      me.device.requestFullscreen();
   } else {
      me.device.exitFullscreen();
   }
});
Parameters:
Name Type Attributes Description
element Element

<optional>

the element to be set in full-screen mode.

unlockOrientation device.js:622
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:
Type Description
boolean

true if the orientation was unsuccessfully unlocked

See: https://developer.mozilla.org/en-US/docs/Web/API/Screen/lockOrientation
unwatchAccelerometer device.js:847
unwatchAccelerometer() → {}

unwatch Accelerometor event

unwatchDeviceOrientation device.js:900
unwatchDeviceOrientation() → {}

unwatch Device orientation event

vibrate device.js:913
vibrate(pattern: number | number<Array>) → {}

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.

// 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);
Parameters:
Name Type Description
pattern number | number<Array>

pattern of vibration and pause intervals

watchAccelerometer device.js:804
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)

// 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
    }
});
Returns:
Type Description
boolean

false if not supported or permission not granted by the user

See:
watchDeviceOrientation device.js:861
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)

// 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
    }
});
Returns:
Type Description
boolean

false if not supported or permission not granted by the user

See:

Powered by webdoc!