September 2014
Beginner
266 pages
5h 38m
English
Just as we enabled touch and then created the function to handle the touches, we will enable the accelerometer and add a function that will get the accelerometer's information and pass it on to this layer.
So, we add the following code to enable the accelerometer:
this->setTouchEnabled(true); this->setAccelerometerEnabled(true);
Next, we need to add the following function in the HelloWorldScene.h file:
virtual void didAccelerate(CCAcceleration* pAccelerationValue);
Then, we add the following code snippet in the HelloWorldScene.cpp file, right under the CCTouchesEnded() function:
void HelloWorld::didAccelerate(CCAcceleration* pAccelerationValue)
{
}Let's now add some code in this function to get data from the accelerometer. ...
Read now
Unlock full access