device
namespace device
boolean
device type and capabilities
Summary
Properties from device
number |
|
number |
|
number |
|
number |
|
boolean |
|
number |
|
number |
|
number |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
string |
|
boolean |
|
number |
|
boolean |
|
boolean |
|
boolean |
|
device.platform |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
Public Properties
accelerationX: number = 0
number
contains the g-force acceleration along the x-axis.
accelerationY: number = 0
number
contains the g-force acceleration along the y-axis.
accelerationZ: number = 0
number
contains the g-force acceleration along the z-axis.
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.
autoFocus: boolean = true
boolean
Specify whether to automatically bring the window to the front
beta: number = 0
number
Device orientation Beta property. Gives angle on tilting a portrait held phone forward or backward
devicePixelRatio: number
number
Ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device.
gamma: number = 0
number
Device orientation Gamma property. Gives angle on tilting a portrait held phone left or right
hasAccelerometer: boolean = --
boolean
Browser accelerometer capabilities
hasDeviceOrientation: boolean = --
boolean
Browser device orientation
hasFullscreenSupport: boolean
boolean
Browser full screen support
hasPointerLockSupport: boolean
boolean
Browser pointerlock api support
isMobile: boolean
boolean
equals to true if a mobile device. (Android | iPhone | iPad | iPod | BlackBerry | Windows Phone | Kindle)
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)
localStorage: boolean
boolean
Browser Local Storage capabilities
(this flag will be set to false if cookies are blocked)
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
}
offscreenCanvas: boolean
boolean
equals to true if the device browser supports OffScreenCanvas.
pauseOnBlur: boolean = true
boolean
Specify whether to pause the game when losing focus
pointerEvent: boolean = --
boolean
True if the browser supports Pointer Events
resumeOnFocus: boolean = true
boolean
Specify whether to unpause the game when gaining focus
screenOrientation: boolean
boolean
Supports the ScreenOrientation API
sound: boolean
boolean
Returns true if the browser/device has audio capabilities.
stopOnBlur: boolean = false
boolean
Specify whether to stop the game when losing focus or not. The engine restarts on focus if this is enabled.
touch: boolean
boolean
Touch capabilities (support either Touch or Pointer events)
Public Methods
enableSwipe(enable: boolean) → {}
enable/disable swipe on WebView.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
enable | boolean |
<optional> |
true |
enable or disable swipe. |
exitFullscreen() → {}
Exit fullscreen mode. Requires fullscreen support from the browser/device.
focus() → {}
Makes a request to bring this device window to the front.
if (clicked) {
me.device.focus();
}
getElement(element: string | HTMLElement) → {HTMLElement}
return the DOM element for the given element name or HTMLElement object
Name | Type | Description |
---|---|---|
element | string | HTMLElement |
the parent element name or a HTMLElement object |
Type | Description |
---|---|
HTMLElement |
the corresponding DOM Element or null if not existing |
getElementBounds(element: string | HTMLElement) → {DOMRect}
returns the size of the given HTMLElement and its position relative to the viewport
Name | Type | Description |
---|---|---|
element | string | HTMLElement |
an HTMLElement object |
Type | Description |
---|---|
DOMRect |
the size and position of the element relatively to the viewport |
getParentBounds(element: string | HTMLElement) → {DOMRect}
returns the size of the given HTMLElement Parent and its position relative to the viewport
Name | Type | Description |
---|---|---|
element | string | HTMLElement |
an HTMLElement object |
Type | Description |
---|---|
DOMRect |
the size and position of the given element parent relative to the viewport |
getParentElement(element: string | HTMLElement) → {HTMLElement}
return the parent DOM element for the given parent name or HTMLElement object
Name | Type | Description |
---|---|---|
element | string | HTMLElement |
the parent element name or a HTMLElement object |
Type | Description |
---|---|
HTMLElement |
the parent Element |
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"
Type | Description |
---|---|
string |
the screen orientation |
getStorage(type: string) → {object}
return the device storage
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type | string |
<optional> |
"local" |
Type | Description |
---|---|
object |
a reference to the device storage |
isFullscreen() → {boolean}
Returns true if the browser/device is in full screen mode.
Type | Description |
---|---|
boolean |
isLandscape() → {boolean}
return true if the device screen orientation is in Portrait mode
Type | Description |
---|---|
boolean |
isPortrait() → {boolean}
return true if the device screen orientation is in Portrait mode
Type | Description |
---|---|
boolean |
isWebGLSupported(options: object) → {boolean}
returns true if the device supports WebGL
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. |
Type | Description |
---|---|
boolean |
true if WebGL is supported |
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.
Name | Type | Description |
---|---|---|
orientation | string | Array<string> |
The orientation into which to lock the screen. |
Type | Description |
---|---|
boolean |
true if the orientation was unsuccessfully locked |
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();
});
Name | Type | Description |
---|---|---|
fn | Function |
the function to be executed |
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();
}
});
Name | Type | Attributes | Description |
---|---|---|---|
element | Element |
<optional> |
the element to be set in full-screen mode. |
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.
Type | Description |
---|---|
boolean |
true if the orientation was unsuccessfully unlocked |
unwatchDeviceOrientation() → {}
unwatch Device orientation event
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);
Name | Type | Description |
---|---|---|
pattern | number | number<Array> |
pattern of vibration and pause intervals |
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
}
});
Type | Description |
---|---|
boolean |
false if not supported or permission not granted by the user |
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
}
});
Type | Description |
---|---|
boolean |
false if not supported or permission not granted by the user |