gpt4 book ai didi

iphone - cocos2d + 加速度计问题

转载 作者:行者123 更新时间:2023-11-29 05:01:09 24 4
gpt4 key购买 nike

我完成了我的游戏(cocos2d),但是当我制作存档(从xcode产品->存档)然后单击共享(获取game.api)然后将其放入itunes中并同步到我的iphone时,加速度计似乎它不起作用我在 5 台设备上测试了游戏,但它不起作用,船总是在固定位置并且它没有移动,但是如果我单击“构建”并从 Xcode 转到它,它对所有开发人员都可以正常工作我使用以下代码的设备:

在初始化中

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

加速度计 Controller :

- (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];
...}

最佳答案

解决方案是替换:

UIAccelerationValue 滚动X;

通过

UIAccelerationValue 滚动X = 0,滚动Y = 0,滚动Z = 0;

关于iphone - cocos2d + 加速度计问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6928548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com