2011-08-03 130 views
0

我完成了我的遊戲(cocos2d),但是當我做一個存檔(從xcode產品 - >存檔),然後點擊共享(獲取game.api),然後把它放入itunes並同步到我的iphone它看起來沒有工作的加速度計我在5個設備上測試了遊戲,並且它沒有工作,船總是在固定的位置,它並沒有移動,但是如果我點擊構建並從xcode去正常工作在所有的開發設備我用下面的代碼:cocos2d +加速度計問題

在init裏面

- (id)init 
{ 
    if ((self = [super init])) 
    { 
    self.isAccelerometerEnabled = YES; 
    [self scheduleUpdate]; 
} 

加速度handeler:

- (void)accelerometer:(UIAccelerometer *)accelerometer 
    didAccelerate:(UIAcceleration *)acceleration { 

#define kFilteringFactor 0.1 
UIAccelerationValue rollingX, rollingY, rollingZ; 

rollingX = (acceleration.x * kFilteringFactor) + 
    (rollingX * (1.0 - kFilteringFactor));  
rollingY = (acceleration.y * kFilteringFactor) + 
    (rollingY * (1.0 - kFilteringFactor));  
rollingZ = (acceleration.z * kFilteringFactor) + 
    (rollingZ * (1.0 - kFilteringFactor)); 

float accelX = acceleration.x - rollingX; 

CGSize winSize = [CCDirector sharedDirector].winSize; 

#define kRestAccelX 0.6 
#define kShipMaxPointsPerSec (winSize.height*0.5) 
#define kMaxDiffX 0.2 

float accelDiffX = kRestAccelX - ABS(accelX); 
float accelFractionX = accelDiffX/kMaxDiffX; 
float pointsPerSecX = kShipMaxPointsPerSec * accelFractionX; 

_shipPointsPerSecY = pointsPerSecX; 

} 

船位置:

- (void)updateShipPos:(ccTime)dt { 

    CGSize winSize = [CCDirector sharedDirector].winSize; 

    float maxY = winSize.height - _ship.contentSize.height/2; 
    float minY = _ship.contentSize.height/2; 
    float newY ; 
    (isYAxisInverted) ? newY = _ship.position.y + (-_shipPointsPerSecY * dt) : newY = _ship.position.y + (_shipPointsPerSecY * dt); 
    newY = MIN(MAX(newY, minY), maxY); 
    _ship.position = ccp(_ship.position.x, newY); 

} 

和在更新:

- (void)update:(ccTime)dt { 
... 
    [self updateShipPos:dt]; 
...} 

回答

1

的解決方案是替代:

UIAccelerationValue rollingX;

通過

UIAccelerationValue rollingX = 0,rollingY = 0,rollingZ = 0;