As everyone is probably aware, the iOS Simulator doesn’t provide any mechanism to simulate the Accelerometer available on actual devices. If you’re using a Macbook, these devices have a freefall sensor in them that can be used to simulate an accelerometer. Whilst it’s not exactly ideal, it can be useful if you wish to test your code easily without having to go through all of the certificate rigmarole.
NB: The details as to how I’ve done this is described below but I am in no way affiliated to the Open Source projects from which I gathered the code. Obviously, use at your own risk.
This documentation relates to the pull request I’ve issued to have these features integrated into the next release of Cocos2D-x.
What you need:
1. You need the code in the aforementioned link above. This utilises the code from: http://code.google.com/p/accelerometer-simulator/wiki/Home and integrates it within Cocos2D-x.
2. You need to download and build the Unimotion code from: https://github.com/gmarik/unimotion3. You need to open up a Terminal window and run the Unimotion binary you created at step 2. Refer to the Unimotion documentation for details on this.
4. You need to add a line to your main.m file:
- You now need to build and then run your App for the iOS Simulator.
You don’t need to do anything else. If Unimotion is running, your App will receive accelerometer updates as you pick up and wiggle your Macbook.
Naturally, you will still need to test and address the functionality of your App with actual devices but at least you can do some rudimentary testing with your code.