2014-03-25 23 views
0

我使用cocos2d來創建一個DNA爲主題的Flappy Bird風格的遊戲(長篇故事,不要指望從中賺錢) 。我試圖根據某一輪達成的分數創建一個獎勵「獎章」的系統。我使用了大於或小於方法來表示是否應該收到某個「獎章」。然而,我的所有獎牌都是在同一時間出現的,而不是基於分數。這裏是適用的代碼:Cocos2d,使用大於和小於一個整數值的限制來顯示一個精靈

NSInteger _points; 

-(BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair hero:(CCNode *)hero goal:(CCNode *)goal { 
    [goal removeFromParent]; 
    _points++; 
    _scoreLabel.string = [NSString stringWithFormat:@"%d", _points]; 
    [self saveState]; 
    [self loadSavedState]; 
if (_points > _highScore) { 
    _highScore = _points; 
} 
return TRUE; 
} 

- (void)gameOver { 
    if (!_gameOver) { 
     _scrollSpeed = 0.f; 
     _gameOver = TRUE; 
     _restartButton.visible = TRUE; 
     _menuButton.visible = TRUE; 
     _gameOverText.visible = TRUE; 
     _score.visible = TRUE; 
     _highScoreValue.visible = TRUE; 
     _highScoreLabel.visible = TRUE; 
     _medal.visible = TRUE; 
     if (9 < _points < 20) { 
      _uracil.visible = TRUE; 
      _uracilLabel.visible = TRUE; 
     } 
     if (19 < _points < 30) { 
      _thymine.visible = TRUE; 
      _thymineLabel.visible = TRUE; 
     } 
     if (29 < _points < 40) { 
      _cytosine.visible = TRUE; 
      _cytosineLabel.visible = TRUE; 
     } 
     if (39 < _points < 50) { 
      _guanine.visible = TRUE; 
      _guanineLabel.visible = TRUE; 
     } 
     if (49 < _points < 60) { 
      _adenine.visible = TRUE; 
      _adenineLabel.visible = TRUE; 
     } 
     _scoreLabel.position = ccp(260, 358); 
     _hero.physicsBody.allowsRotation = FALSE; 
     [_hero stopAllActions]; 
     CCActionMoveBy *moveBy = [CCActionMoveBy actionWithDuration:0.2f position:ccp(-5, 5)]; 
     CCActionInterval *reverseMovement = [moveBy reverse]; 
     CCActionSequence *shakeSequence = [CCActionSequence actionWithArray:@[moveBy, reverseMovement]]; 
     CCActionEaseBounce *bounce = [CCActionEaseBounce actionWithAction:shakeSequence]; 
     [self runAction:bounce]; 
    } 
} 

我怎樣才能使使「金牌」出現時,他們都應該基於分數? 感謝您的幫助。

回答

1

替換這些

if (9 < _points < 20) 

隨着

if (_points > 9 && _points < 20) 
+0

運行完美,謝謝。 – camyoung54