在Xcode5中,我的游戏运行得很好,当我的电脑更新到Xcode6时,它就出现了buggy。我不知道到底发生了什么。我认为这可能与连接到显示分数的文本的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;
}发布于 2014-11-11 10:45:33
问题将在于调用在不应该重置游戏的时间重置游戏的方法。你遗漏了碰撞方法,所以我不知道这个方法是做什么的。我不认为在发布的代码中有任何会重置游戏的东西。
我认为问题可能出在你的碰撞方法上,因为你在一个计时器上调用了它,这个计时器与你的评分方法是一样的。当得分达到1时,它们都会被调用,并且评分方法中没有任何会重置游戏的内容。
https://stackoverflow.com/questions/26855476
复制相似问题