2012-11-09 2 views
4

좋아,이게 내 첫 번째 게시물이고, 나는 Xcode와 Objective C에서 여전히 아주 새로운 것이다. Iv'e는 지난 몇 주 동안 스스로 가르쳤다. 어쨌든, 헬리콥터를 조종하고 동전이 떨어지는 작은 게임을 만들어 연습합니다. 나는 개체 충돌 방법으로 약간의 문제를 가지고있다. 가장 큰 문제는 충돌이 성공한 후 헬리콥터가 자동으로 시작 위치로 이동된다는 것입니다. 헬리콥터 UIImage가 새로운 위치에 머물러 있기를 바랍니다. 필자는 코드의 모든 라인을 점검했으며 어디에서 Helicopter.frame을 원래 위치로 다시 만들 것인지를 호출하지 않습니다.UIImage 충돌 후 원하지 않는 움직임

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *UserMoveTouch = [touches anyObject]; 
    CGPoint pos = [UserMoveTouch locationInView: self.view]; 
    if(pos.x<356) 
    { 
     [UIView beginAnimations:@"CopterMoveTo" context:NULL]; 
     [UIView setAnimationDuration: .5]; 
     [UIView setAnimationBeginsFromCurrentState:YES]; 

     CopterPlayer.center = [UserMoveTouch locationInView:self.view]; 

     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
     [UIView commitAnimations]; 
    } 
} 


-(void)CopterCollisionCheck 
{ 
    if(CGRectIntersectsRect(Coin1.frame, CopterPlayer.frame)) 
    { 
     SystemSoundID soundID; 
     NSString *CoinSound=[[NSBundle mainBundle] 
          pathForResource:@"GetCoin" ofType:@"wav"]; 
     AudioServicesCreateSystemSoundID((__bridge CFURLRef) 
             [NSURL fileURLWithPath:CoinSound], & soundID); 
     AudioServicesPlaySystemSound(soundID); 
     Coin1.frame=CGRectMake(Coin1.center.x+150,15,20,23); 
     if (MultiplierX==1) 
     { 
      ScoreValue=ScoreValue+1; 
     } 
     else if(MultiplierX==2) 
     { 
      ScoreValue=ScoreValue+2; 
     } 
     else if(MultiplierX==3) 
     { 
      ScoreValue=ScoreValue+3; 
     { 
    } 
    ScoreValueLabel.text = [NSString stringWithFormat:@"%d",ScoreValue]; 


} 


-(void)CopterCollisionTimer 
{ 
    [NSTimer scheduledTimerWithTimeInterval:0.35 target:self    
    selector:@selector(CopterCollisionCheck) userInfo:nil repeats:YES]; 
} 

코드를 붙여 넣은 괄호 등을 잊어 버렸을 경우 사과 드리며이 사이트의 게시물 서식 지정에는 사용하지 마십시오. noobie 포스트를 먼저 기억하십시오! 도움이 크게 감사! : D

답변

0

pshhh 이것은 내가 얼마나 노 보쉬인지 보여주는 것입니다 ... 게임 플레이 중에 레이블 텍스트 값을 계속 변경하면 UIImages가 괴물이 될 수도 있습니다. 텍스트 필드로 변경되었으며 모두 잘되었습니다.