1
장치를 왼쪽이나 오른쪽으로 기울여 구를 이동하려고합니다. 내가 지금 data.acceleration.y -> Y 축을 말하는 동안 장치를 위아래로 기울여야한다는 것을 제외하고 지금 당장 가지고있는 코드가 작동하고 있습니까? 어떤 도움이 정말 감사합니다기울이기 장치로 노드 이동
motionManager = [[CMMotionManager alloc] init];
if ([motionManager isAccelerometerAvailable] == YES) {
[motionManager startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc] init]
withHandler:^(CMAccelerometerData *data, NSError *error)
{
float destX, destY;
float currentX = sphereNode.position.x;
float currentY = sphereNode.position.y;
BOOL shouldMove = NO;
if(data.acceleration.y < -0.25) { // tilting the device to the right
destX = currentX + (data.acceleration.y * kPlayerSpeed);
destY = currentY;
shouldMove = YES;
} else if (data.acceleration.y > 0.25) { // tilting the device to the left
destX = currentX + (data.acceleration.y * kPlayerSpeed);
destY = currentY;
shouldMove = YES;
}
if(shouldMove) {
SKAction *action = [SKAction moveTo:CGPointMake(destX, destY) duration:1];
[sphereNode runAction:action];
}
}];
}
:
여기 내 코드입니다!
나는 y를 x로 변경하여 문제를 해결할 수있었습니다. 이 문서를 가져 주셔서 감사합니다! –