好的,这是我的第一篇文章,我在Xcode和Objective C上仍然非常新。过去几周我一直在自我教学。无论如何,我通过制作一个小型游戏来练习,你可以控制直升机并收集掉落的硬币。我在使用对象碰撞方法时遇到了一些麻烦。最大的问题是,在成功碰撞后,直升机将自动移回其起始位置,这是我不想要的。我希望直升机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
答案 0 :(得分:0)