I was messing around the the HTML5 implementation of accelerometer events and as far as I could see, it does not seem to detect the current platform and perform key bindings for the events the same way the C++ version does.
Is this feature implemented anywhere and I just missed it, or is it really not there? If so, any reason why this is the case?
Thanks in advance!
In case someone is interested, this is how I got around this limitation:
First I added this method to a class that extends cc.Layer:
keysToAccelerometer:function(key){
switch (key) {
case cc.KEY.left:
var accelEvent = {timestamp: new Date().getTime(), x: -0.2, y: 0, z: 0};
this.onAccelerometer(accelEvent);
break;
case cc.KEY.right:
var accelEvent = {timestamp: new Date().getTime(), x: 0.2, y: 0, z: 0};
this.onAccelerometer(accelEvent);
break;
case cc.KEY.up:
var accelEvent = {timestamp: new Date().getTime(), x: 0, y: 0.2, z: 0};
this.onAccelerometer(accelEvent);
break;
case cc.KEY.down:
var accelEvent = {timestamp: new Date().getTime(), x: 0, y: -0.2, z: 0};
this.onAccelerometer(accelEvent);
break;
case cc.KEY.comma:
var accelEvent = {timestamp: new Date().getTime(), x: 0, y: 0, z: 0.2};
this.onAccelerometer(accelEvent);
break;
case cc.KEY.period:
var accelEvent = {timestamp: new Date().getTime(), x: 0, y: 0, z: -0.2};
this.onAccelerometer(accelEvent);
break;
}
}
And then, in my onKeyDown method, I add the following:
onKeyDown:function(key) {
/* ... */
this.keysToAccelerometer(key);
}
Not sure if this is a perfect solution, but it works pretty well for debugging purposes
Cocos2d-html5 has implemented accelerometer in /cocos2d/platform/accelerometer.js.
There are also some accelerometer tests in test case/event tests.
1 Like