开发者

cocos2d + Accelerometer issue

I finished my game (cocos2d) but when I make an archive (from xcode product->Archive) then click on share (to get game.api) then put it in the itunes and sync to my iphone the accelerometer it seem that it didn't work I tested the game in 5 devices and it didn't work, the ship always in fix place and it didn't move, But if I click build and go from the xcode it work properly on all the developer devices I use the code below :

inside the init

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

accelerometer 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;

}

ship position:

- (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 + (_sh开发者_高级运维ipPointsPerSecY * dt);
    newY = MIN(MAX(newY, minY), maxY);
    _ship.position = ccp(_ship.position.x, newY);

}

and in the update :

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


the solution is to replace:

UIAccelerationValue rollingX;

by

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜