1
이것은 (일명 ball
가 label
와 동기화) 플레이어를 이동하는 나의 방법이다 동적되지 않습니다 :있는 UIImageView 프레임은
int x2 = self.ball.frame.origin.x;
int y2 = self.ball.frame.origin.y;
double distance = sqrt(pow((x2 - coords.x), 2.0) + pow((y2 - coords.y), 2.0));
// 140 is just an arbitrary multiplier
NSTimeInterval time = distance/140;
animating = YES;
[UIView animateWithDuration:time delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
[self.ball setFrame:CGRectMake(coords.x, coords.y, 48, 48)];
[self.label setFrame:CGRectMake(coords.x - 30, coords.y - 25, 108, 20)];
} completion:^(BOOL finished) {
animating = NO;
}];
이 코드는 하나 개의 탭에서 작동하지만, 플레이어가 자신의 행동을 리디렉션 할 때 (다른 곳에서 접촉 여전히 움직이는 동안, 따라서 UIViewAnimationOptionBeginFromCurrentState
), 거리가 잘못되었습니다. 이는 프레임이 애니메이션이 종료 된 지점 대신 첫 번째 터치의 끝 지점으로 설정되기 때문입니다.
UIView 애니메이션은 게임 플레이 시나리오를위한 것이 아닙니다. "자신의 이동 방향"에 대한 전체적인 개념은 중요한 부분입니다. UIView 애니메이션은 UIView 애니메이션으로 할 수 있지만, UIView 애니메이션은 실제 애니메이션 엔진의 라이브 프레임 프레임이 아니기 때문에 총 해킹입니다. SpriteKit을 사용하는 것이 좋습니다. – matt