Projects > cpp > Issues > Feature #242

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

support accelerometer on android

Feature #242 [Closed]
zhangxm 2010-12-05 18:10 . Updated almost 2 years ago
zhangxm 2010-12-18 01:11
  • Target version changed from cocos2d-0.99.4-x-0.7.1 to cocos2d-0.99.5-x-0.7.2 2011-01-16 22:02
  • Target version changed from cocos2d-0.99.5-x-0.7.2 to cocos2d-0.99.5-x-0.8.0 2011-01-27 17:49
  • Assignee deleted (zhangxm) 2011-01-27 18:02
  • Project changed from 5 to cocos2d-x 2011-01-27 18:03
  • Category set to 2
Macarse 2011-01-27 18:06

To do this SensorManager is needed and unfortunately it can’t be used from the NDK.

Check Dianne Hackborn’s reply about the subject:\_thread/thread/f299413e610c7e93?hl=en&pli=1

zhangxm 2011-01-27 18:32

Yes, so we should get the information from java. ndk-r5 supports it, but it is not so popular now. 2011-01-27 22:03
  • Assignee set to Macarse

Carlos, about the answer of your post\#post-72989
Before designing the interface of our cross-platform layer, we dicussed on some different solutions.
e..g Design the interfaces by us? use openKODE of khronos? At last we decide to copy the APIs of iOS. So the UIEvent, is abstract to cocos2d::UIEvent, and in future cocos2d::ccxEvent; UIAccelerometer to cocos2d::UIAccelerometer or cocos2d::ccxAccelerometer. It’s easy for iOS developers to learn and use, to port their games. In the other hand, we cannot desgin better than apple.

So the accelerometer support on android, is to wrap android accelerometer APIS to the iOS UIAccelerometer interfaces. You needn’t implement all the interfaces of it, just fit the cocos2d-x invoking is enough.

Macarse 2011-01-30 15:20

I just pushed a pull request for this:
I added a bunch of comments to the commit, let me know what do you think.

Bonus Track:
Difference of speed between the Nexus one and Nexus S.\_rfeY 2011-01-30 18:13

You’re right, but not completely.
Take a look in cocos2dx/platform/uphone/CCXEGLView_uphone.cpp, line 280, in case MESSAGE_SENSORS_DATA
uphone referenced to android’s accelerometer design, we found it’s different from iphone.

                // convert the data to iphone format
                UIAcceleration AccValue;
                AccValue.x = -(data.acceleration.x / TG3_GRAVITY_EARTH);
                AccValue.y = -(data.acceleration.y / TG3_GRAVITY_EARTH);
                AccValue.z = -(data.acceleration.z / TG3_GRAVITY_EARTH);
                AccValue.timestamp = (double) TimGetTicks() / 100;

                // call delegates' didAccelerate function

the TG3_GRAVITY_EARTH is defined in uphone sdk

#define TG3_GRAVITY_EARTH                   (9.80665f)
zhangxm 2011-02-23 17:36
  • Status changed from New to Closed 2012-05-25 08:18
  • Project changed from cocos2d-x to cpp
  • Category deleted (2)
  • Target version deleted (cocos2d-0.99.5-x-0.8.0)
agenindonesia 2014-11-25 20:32 Agen Texas Poker Dan Domino Online Indonesia Terpercaya
OK, I’ve updated the announcement and added a link to zipball on google code. Thank you for reminding me.
Agen Indonesia | Agen Bola | Poker Indonesia

ionliga 2014-11-28 14:37

The optimization introduces a bug where the priority and Touch Mode will not get changed if the list is locked.
The most straight forward fix is to merge the pHandlersToAdd and pHandlersToRemove into a queue and process through all of them in the order they are received Agen Texas Poker dan Domino Online Indonesia Terpercaya | Agen Bola | Taruhan Bola | Agen Bola | Agen Judi Bola Online, Agen Judi Casino Online Indonesia Terpercaya

Atom PDF

Start date:2010-12-05
Due date:
% Done:


Target version:-
Estimated time:8.00 points

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.