craftyjs.github.com

Crafty.device

Back to top

Crafty.mobile

Determines if Crafty is running on mobile device.

If Crafty.mobile is equal true Crafty does some things under hood:

- set viewport on max device width and height
- set Crafty.stage.fullscreen on true
- hide window scrollbars

See Also

Back to top

Crafty.device.deviceOrientation

public Crafty.device.deviceOrientation(Function callback)

callback
Callback method executed once as soon as device orientation is change

Do something with normalized device orientation data:

{
  'tiltLR'    :   'gamma the angle in degrees the device is tilted left-to-right.',
  'tiltFB'    :   'beta the angle in degrees the device is tilted front-to-back',
  'dir'       :   'alpha the direction the device is facing according to the compass',
  'motUD'     :   'The angles values increase as you tilt the device to the right or towards you.'
}

Example

// Get DeviceOrientation event normalized data.
Crafty.device.deviceOrientation(function(data){
    console.log('data.tiltLR : '+Math.round(data.tiltLR)+', data.tiltFB : '+Math.round(data.tiltFB)+', data.dir : '+Math.round(data.dir)+', data.motUD : '+data.motUD+'');
});

See browser support at http://caniuse.com/#search=device orientation.

Back to top

Crafty.device.deviceMotion

public Crafty.device.deviceMotion(Function callback)

callback
Callback method executed once as soon as device motion is change

Do something with normalized device motion data:

{
    'acceleration' : ' Grab the acceleration including gravity from the results',
    'rawAcceleration' : 'Display the raw acceleration data',
    'facingUp' : 'Z is the acceleration in the Z axis, and if the device is facing up or down',
    'tiltLR' : 'Convert the value from acceleration to degrees. acceleration.x is the acceleration according to gravity, we'll assume we're on Earth and divide by 9.81 (earth gravity) to get a percentage value, and then multiply that by 90 to convert to degrees.',
    'tiltFB' : 'Convert the value from acceleration to degrees.'
}

Example

// Get DeviceMotion event normalized data.
Crafty.device.deviceMotion(function(data){
    console.log('data.moAccel : '+data.rawAcceleration+', data.moCalcTiltLR : '+Math.round(data.tiltLR)+', data.moCalcTiltFB : '+Math.round(data.tiltFB)+'');
});

See browser support at http://caniuse.com/#search=motion.