그래서 처음 개발 한 첫 번째 연습용 게임인데 가속도계를 처음 사용하기 때문에 대답이 확실하다면 사전에 사과하십시오. 코드와 설명으로도 대답 해주십시오.Accelerometer Tilt Issue
게임의 일부로 볼을 화면 주위에 굴려 놓았습니다. 공은 기울기에 따라 움직입니다. 이 앱의 기기 방향은 가로 방향 일뿐입니다. 전화 화면을 오른쪽으로 잡고 휴대 전화를 위아래로 기울이면 볼이 적절하게 움직입니다. (볼이 위로 굴러 내려 가기 끝을 기울이십시오, 볼이 아래로 내려 오도록 아래쪽 끝을 기울이십시오). 그래서 그 두 경사는 괜찮습니다. 이제 화면을 왼쪽으로 기울이면 볼이 오른쪽으로 굴러 가고 그 반대도 마찬가지입니다. 내가 원하는 것은 화면이 왼쪽으로 기울고 왼쪽으로 공이 기울고 화면이 오른쪽으로 기울고 공이 오른쪽으로가는 것입니다. 이 코드는 어떻게 수정합니까? 아마도 두 줄을 바꾸는 것만 큼 쉬운 걸 압니다.
//delegate method
-(void)outputAccelertionData:(CMAcceleration)acceleration
{
currentMaxAccelX = 0;
currentMaxAccelY = 0;
if(fabs(acceleration.x) > fabs(currentMaxAccelX))
{
// this needs to be currentMaxAccelY not currentMaxAccelX for those of you thinking this is the solution
currentMaxAccelY = acceleration.x;
}
if(fabs(acceleration.y) > fabs(currentMaxAccelY))
{
// this needs to be currentMaxAccelX not currentMaxAccelY for those of you thinking this is the solution
currentMaxAccelX = acceleration.y;
}
}
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
float maxY = 480;
float minY = 0;
float maxX = 320;
float minX = 0;
float newY = 0;
float newX = 0;
//Im pretty sure the problem is in this if statement as this is what deals with the left and right tilt
if(currentMaxAccelX > 0.05){
newX = currentMaxAccelX * 10;
}
else if(currentMaxAccelX < -0.05){
newX = currentMaxAccelX*10;
}
else{
newX = currentMaxAccelX*10;
}
newY = currentMaxAccelY *10;
newX = MIN(MAX(newX+self.ball.position.x,minY),maxY);
newY = MIN(MAX(newY+self.ball.position.y,minX),maxX);
self.ball.position = CGPointMake(newX, newY);
}