在Xcode 5中,我的游戏工作得很好,当我的计算机更新到Xcode 6时,它变得越来越多。我不确切知道发生了什么。我认为它可能需要与显示分数的文本连接的NSStrings做一些事情。每当得分变为1时,游戏就会重置。也许它在touchesBegan:withEvent:
?
游戏是一艘穿过洞穴的潜水艇,每半秒钟就能获得积分,并在潜水艇击中硬币时赚取金币。下面是代码部分,但我不知道错误来自何处。
-(void)NewGame{
Coin.hidden = YES;
Coin2.hidden = YES;
Ruby.hidden = YES;
Ruby2.hidden = YES;
Intro1.hidden = NO;
Intro2.hidden = NO;
Intro3.hidden = NO;
Intro8.hidden = NO;
IntroC.hidden = NO;
Start = YES;
ScoreNumber = 0;
Score.text = [NSString stringWithFormat:@"Score: 0"];
CoinNumber = 0;
CoinCount.text = [NSString stringWithFormat:@"Coins: 0"];
Intro3.text = [NSString stringWithFormat:@"HighScore: %i", HighScoreAttack];
IntroC.text = [NSString stringWithFormat:@"Total Coins: %i", TotalCoins];
}
-(void)Fishmove {
[self Collision];
Submarine.center = CGPointMake(Submaine.center.x, Submarine.center.y + y);
Obstacle.center = CGPointMake(Obstacle.center.x - 10, Obstacle.center.y);
Obstacle2.center = CGPointMake(Obstacle2.center.x - 10, Obstacle2.center.y);
Bottom1.center = CGPointMake(Bottom1.center.x - 10, Bottom1.center.y);
Bottom2.center = CGPointMake(Bottom2.center.x - 10, Bottom2.center.y);
Bottom3.center = CGPointMake(Bottom3.center.x - 10, Bottom3.center.y);
Bottom4.center = CGPointMake(Bottom4.center.x - 10, Bottom4.center.y);
Bottom5.center = CGPointMake(Bottom5.center.x - 10, Bottom5.center.y);
Bottom6.center = CGPointMake(Bottom6.center.x - 10, Bottom6.center.y);
Bottom7.center = CGPointMake(Bottom7.center.x - 10, Bottom7.center.y);
Top1.center = CGPointMake(Top1.center.x - 10, Top1.center.y);
Top2.center = CGPointMake(Top2.center.x - 10, Top2.center.y);
Top3.center = CGPointMake(Top3.center.x - 10, Top3.center.y);
Top4.center = CGPointMake(Top4.center.x - 10, Top4.center.y);
Top5.center = CGPointMake(Top5.center.x - 10, Top5.center.y);
Top6.center = CGPointMake(Top6.center.x - 10, Top6.center.y);
Top7.center = CGPointMake(Top7.center.x - 10, Top7.center.y);
Coin.center = CGPointMake(Coin.center.x - 10, Coin.center.y);
Coin2.center = CGPointMake(Coin2.center.x - 10, Coin2.center.y);
Ruby.center = CGPointMake(Ruby.center.x - 10, Ruby.center.y);
Ruby2.center = CGPointMake(Ruby2.center.x - 10, Ruby2.center.y);
if (Obstacle.center.x < 0) {
Obstacle.hidden = NO;
RadnomPosition = arc4random() %75;
RadnomPosition = RadnomPosition +110;
Obstacle.center = CGPointMake(560, RadnomPosition);
}
if (Obstacle2.center.x < 0) {
Obstacle2.hidden = NO;
RadnomPosition = arc4random() %75;
RadnomPosition = RadnomPosition + 110;
Obstacle2.center = CGPointMake(560, RadnomPosition);
}
if (Coin.center.x < 0) {
Coin.hidden = NO;
RadnomPosition = arc4random() %250;
RadnomPosition = RadnomPosition +110;
Coin.center = CGPointMake(560, RadnomPosition);
}
if (Coin2.center.x < 0) {
Coin2.hidden = NO;
RadnomPosition = arc4random() %150;
RadnomPosition = RadnomPosition + 110;
Coin2.center = CGPointMake(560, RadnomPosition);
}
if (Coin.center.y > 250) {
Coin.hidden = YES;
}
if (Coin2.center.y > 250) {
Coin2.hidden = YES;
}
}
-(void)Scoring{
ScoreNumber = ScoreNumber + 1;
Score.text = [NSString stringWithFormat:@"Score: %i",ScoreNumber];
}
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if (Start == YES) {
Intro1.hidden = YES;
timer = [NSTimer scheduledTimerWithTimeInterval:0.05 target: self selector:@selector(Fishmove) userInfo:nil repeats:YES];
Scorer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(Scoring) userInfo:nil repeats:YES];
CoinScorer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(Collision) userInfo:nil repeats:YES];
Start = NO;
Obstacle2.hidden = NO;
Coin.hidden = NO;
Coin2.hidden = NO;
RadnomPosition = arc4random() %75;
RadnomPosition = RadnomPosition + 110;
Obstacle.center = CGPointMake(570, RadnomPosition);
RadnomPosition = arc4random() %75;
RadnomPosition = RadnomPosition + 110;
Obstacle2.center = CGPointMake(855, RadnomPosition);
RadnomPosition = arc4random() %75;
RadnomPosition = RadnomPosition + 110;
Coin.center = CGPointMake(712.5, RadnomPosition);
RadnomPosition = arc4random() %75;
RadnomPosition = RadnomPosition + 110;
Coin2.center = CGPointMake(997.5, RadnomPosition);
RadnomPosition = arc4random() %75;
RadnomPosition = RadnomPosition + 110;
Ruby.center = CGPointMake(712.5, RadnomPosition);
RadnomPosition = arc4random() %75;
RadnomPosition = RadnomPosition + 110;
Ruby2.center = CGPointMake(997.5, RadnomPosition);
RadnomPosition = arc4random() %55;
Top1.center = CGPointMake(560, RadnomPosition);
RadnomPosition = RadnomPosition + 265;
Bottom1.center = CGPointMake(560, RadnomPosition);
RadnomPosition = arc4random() %55;
Top2.center = CGPointMake(640, RadnomPosition);
RadnomPosition = RadnomPosition + 265;
Bottom2.center = CGPointMake(640, RadnomPosition);
RadnomPosition = arc4random() %55;
Top3.center = CGPointMake(720, RadnomPosition);
RadnomPosition = RadnomPosition + 265;
Bottom3.center = CGPointMake(720, RadnomPosition);
RadnomPosition = arc4random() %55;
Top4.center = CGPointMake(800, RadnomPosition);
RadnomPosition = RadnomPosition + 265;
Bottom4.center = CGPointMake(800, RadnomPosition);
RadnomPosition = arc4random() %55;
Top5.center = CGPointMake(880, RadnomPosition);
RadnomPosition = RadnomPosition + 265;
Bottom5.center = CGPointMake(880, RadnomPosition);
RadnomPosition = arc4random() %55;
Top6.center = CGPointMake(960, RadnomPosition);
RadnomPosition = RadnomPosition + 265;
Bottom6.center = CGPointMake(960, RadnomPosition);
RadnomPosition = arc4random() %55;
Top7.center = CGPointMake(1140, RadnomPosition);
RadnomPosition = RadnomPosition + 265;
Bottom7.center = CGPointMake(1140, RadnomPosition);
}
y = -7;
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
y = 7;
}
答案 0 :(得分:0)
问题在于调用不应该重置游戏的方法。你遗漏了你的碰撞方法,所以我不知道那个方法做了什么。我没有看到发布的代码中的任何内容会重置游戏。
我认为问题可能在于你的碰撞方法,因为你有一个调用与你的评分方法相同的计时器。当得分变为1时,它们都被调用,而得分方法中没有任何可以重置游戏的东西。