나는 사용자가 상단의 상태 표시 줄에 병 하나를 던져서 깰 수있는 간단한 게임을하고있다. 사용자가 병 (UIView)을 잡으면 테스트하기 위해 touchesMoved를 사용하고 있으며 사용자의 손가락을 튀기는 방향에 응답하여 throw됩니다. 던지는 부분에 대해서는 작동하지만, 부러 지거나 부러진 병 png로 바꾸기를 원합니다. 프레임에서 벗어나면이 부분에 두통이 생깁니다. 여기에 코드의 일부입니다 지금은움직이는 물체가 프레임에 닿았을 때 어떻게 멈출 수 있습니까?
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *aTouch = [touches anyObject];
CGPoint location = [aTouch locationInView:self.view];
throwView = [self.view hitTest:location withEvent:nil];
//if the movement not on self.view, it's on the bottle.
if (bottleView != self.view) {
CGPoint loc = [aTouch locationInView:self.bottleView];
CGPoint prevloc = [aTouch previousLocationInView:self.bottleView];
//getting the finger moment
myFrame = self.bottleView.frame;
deltaX = loc.x - prevloc.x;
deltaY = loc.y - prevloc.y;
myLocation = bottleView.center;
//Here I try to multiply the finger movement to throw the bottles
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
myFrame.origin.x += deltaX*7.0;
myFrame.origin.y += deltaY*7.0;
[self.bottleView setFrame:myFrame];
[bottleView setNeedsDisplay];
[UIView commitAnimations];
//if it hits the top of the frame..
if (myFrame.origin.y <=20){
[self hitTheTop];
}
}}
//this part gives me headache, I repeat the code again otherwise the bottle is broken before hitting the top.
-(void) hitTheTop{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
myFrame.origin.x += deltaX*7.0;
myFrame.origin.y += deltaY*7.0;
[self.bottleView setFrame:myFrame];
[bottleView setNeedsDisplay];
[UIView commitAnimations];
//I calculate the slope and find where x should be when y is 0, 40 is half width of the bottle
myFrame.origin.x = myLocation.x + (myLocation.y/(-deltaY/deltaX)) - 40;
myFrame.origin.y = 0;
UIImageView *bottleBroken=
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"broken.png"]];
[bottleBroken setFrame:CGRectMake(-20, -30, 130, 180)];
[self.bottleView setFrame:myFrame];
[bottleView addSubview:bottleBroken];
}
, 병이 프레임 밖으로 날아 처음으로 내가 얻을, 아주 잠시 동안, 그것은 프레임의 가장자리에 다시 나타납니다 이미 그것을 고장 정말로 부 자연스럽게 보입니다. 사실 나는 던지기를 표시하는 타이머를 넣으 려하고 더 잘 관리 할 수 있습니다. 그러나 나는 타이머가 없다면 그것을 할 수있는 더 쉬운 방법이 있다면 탐험하고 싶다.
"GRSceneController"란 무엇인가요? OPENGL에서 개발자 라이브러리를 찾을 수 없습니까? 내 생각에 내가 아는 바를 넘어선 것 같아. 미안 해요, 객관적으로는 아직 새로운데, 심지어 오픈 GL에도 준비가 안됐어. – Walter
아, 그건 내가 만든 장면 컨트롤러 일 뿐이니까, 어디서나 찾을 수는 없을 것입니다. 그것은 단지 일반적인 지침으로 의미가 있으며, 복사 및 붙여 넣기가 아닙니다. –