I have implemented a space shooter game project with Cocos2d 2.0 and a UIAccelleration controller. The UIAccelleration as some drawbacks:
- it requires calibration
- it depends on actual accelleration and hence it could lead to loose sensitivity as it is hard to find an optimal configuration
I have found some tutorial on how to use Gyroscope instead (I am aware that is only on latest iPhones/IPods but as I am using already Cocos2d 2.0 -> OpenGL 2.0 ES it shouldn't matter).
Are there any test projects where I can try the Gyroscope? It is still not 100% clear to me how it works and if this will bring a real change on my code.
That's my UIAcceleration based controller:
#define kHeroMovementAction 1
#define kPlayerSpeed 100
- (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
if (calibrationLayer.visible){
[self evaluateCalibration:acceleration];
initialAccelleration=acceleration;
return;
}
if([self evaluatePause]){
return;
}
ShooterScene * shooterScene = (ShooterScene *) [self parent];
ShipEntity *playerSprite = [shooterScene playerShip];
float accellerationtSensitivity = 0.5f;
/
UIAccelerationValue xAccelleration = acceleration.x - initialAccelleration.x;
UIAccelerationValue yAccelleration = acceleration.y - initialAccelleration.y;
if(xAccelleration > 0.05 || xAccelleration < -0.05) {
[playerSprite setPosition:CGPointMake(playerSprite.position.x + xAccelleration * 80, playerSprite.position.y + yAccelleration * 80)];
}
else if(yAccelleration > 0.05 || yAccelleration < -0.05)
{
[playerSprite setPosition:CGPointMake(playerSprite.position.x + xAccelleration * 80, playerSprite.position.y + yAccelleration * 80)];
}
}