わかりました、これは私の最初の投稿です。私はまだ Xcode と Objective C の初心者です。ここ数週間、独学で勉強しています。とにかく、ヘリコプターを操作して落ちるコインを集める小さなゲームを作って練習しています。ただし、オブジェクトの衝突方法に問題があります。最大の問題は、衝突が成功した後、ヘリコプターが自動的に開始位置に戻ることです。これは望ましくありません。Helicopter UIImage を新しい場所にとどめたい。コードのすべての行をチェックしましたが、元の位置に Helicopter.frame を再作成するために呼び出す場所はありません。
-(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