So I started learning some Box2D to improve my skills in game programming. Box2D is a physics engine written in C++. Many games use a graphics engine but not a physics engine. The graphics engine usually accelerates the GPU graphics, but what makes movements look realistic is the physics engine.
Because Box2D is written in C++, you cannot simply use it in your iOS project, but thanks to Objective-C++ support, you can change your file extensions to .mm and then simply use C++ in your Objective-C project.
In this example, I’m not using a graphics engine, only Box2D and basic UIKit elements (UIView). The next step would be to do a similar example using a graphics engine like Cocos2D.
Source code: https://github.com/dimme/Box2DTest
do you can send to me this application’s source code?
Here you go: https://github.com/Dimme/Box2DTest
Hi Dimme,
I got your source code and tested it on iPhone 5,when I stopped accelerating for over 3 seconds,the uiviews all did not move any more,I NSLog’ed ,the accelerometer and tick functions were still working ,could you please tell me why it happened ?
Best,
Peter
Try changing the
#define kAccelerometerFrequency 100.0
in ViewController.mm to something else.