Hi
I have just completed my game with cocos2d, however I go and build for release now (have always been building for debug) and now when I launch the game the accelerometer is screwed up.
It worked wonderfully in debug mode, with no issues at all.
What its meant to do: Tilt left and right to move player left and right on screen.
Whats wrong with release build: Now the accelerometer no longer seems centred. Having flat in hand does the same as if I was tilting loads to the left, requires me to tilt the iphone completely to the right 90 degrees rather than naturally flat in hand to stay still, not move player. It seems offset.
My accelerometer code:
Inside init method:
[self schedule:@selector (update:)];
-(void) update: (ccTime) dt {
//Update the players position from the accelerometer.
[_player1 setPosition:lastPosition];
_player2.rotation = _player1.rotation;
if (_player1.position.x >= 58 && _player1.position.x <= 262) {
_player2.opacity = 0;
}
if (_player1.position.x > 262) {
_player2.opacity = 255;
[_player2 setPosition:ccp(newX - 319, _player1.position.y)];
if (_player2.position.x >= 58) {
[_player1 setPosition:ccp(newX - 319, _player1.position.y)];
}
}
if (_player1.position.x < 58) {
_player2.opacity = 255;
[_player2 setPosition:ccp(newX + 319, _player1.position.y)];
if (_player2.position.x <= 262) {
[_player1 setPosition:ccp(newX + 319, _player1.position.y)];
}
}
}
- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration {
float accelJitter = 0.01;
float playerJitter = 1.0;
const float kFilteringFactor = 0.1;
UIAccelerationValue rollingY;
BOOL shouldMove = NO;
rollingY = ((acceleration.x * kFilteringFactor) + (rollingY * (1.0 - kFilteringFactor)));
float accelY = acceleration.x - rollingY;
newX = _player1.position.x - (40 *-accelY);
if (accelY < -accelJitter || accelY > accelJitter) shouldMove = YES;
if (shouldMove) {
if (newX < -60) {
newX = -60;
}
if (newX > 380) {
newX = 380;
}
if (((newX - _player1.position.x) > playerJitter) ||
((_player1.position.x - newX) > playerJitter)) {
[self setLastPosition:CGPointMake(newX, _player1.position.y)];
}
}
}