Unwanted movement after a UIImage collision

Well, this is my first post, and I'm still VERY new to Xcode and Objective C. For several weeks I myself studied. In any case, Im practicing making a little game where you control a helicopter and collect coins that fall. However, I had problems with the collision method of objects. The biggest problem is that after a successful collision, the helicopter will automatically be returned to its original location, which I do not want. I want the UIImage helicopter to stay in its new location. I checked every line of my code and not where I urge to recreate the Helicopter in its original position.

-(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]; } 

We apologize if I forget the brackets or something with the code insert, and not use it to format messages on this site. Remember the first noobie post! Help is much appreciated !: D

+4
source share
1 answer

pshhh this will show how noobish I am ... I didn’t realize that constantly changing the value of the shortcut text during the game would make UIImages a freak. Changed it to a text box, and all is well :)

0
source

Source: https://habr.com/ru/post/1445023/


All Articles