May 16, 2013 - No Comments!

Lifelike gravity with Accelerometer in Cocos2D + Box2D, Xcode Sample

Small code snippet reference for getting lifelike gravity from your accelerometer in your projects. This is for Cocos2D and Box2D but is easily changeable to your project needs whichever language you program in.

- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
b2Vec2 gravity ( 9.8 * acceleration.x, acceleration.y * 9.8);

Published by: nick in Code Sample, IOS/ XCode

Leave a Reply