0

我正在使用 cocos2d 创建一个以 DNA 为主题的 Flappy Bird 风格的游戏(说来话长,不要指望从中赚钱)。我正在尝试创建一个基于某一回合达到的分数来奖励“奖牌”的系统。我正在使用大于和小于方法来指示是否应该收到某个“奖章”。但是,我的所有奖牌都是同时出现的,而不是根据分数单独显示。这是适用的代码:

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];
    }
}

我怎样才能让“奖牌”在他们应该基于分数的时候出现?谢谢您的帮助。

4

1 回答 1

1

Replace these

if (9 < _points < 20)

With

if (_points > 9 && _points < 20)
于 2014-03-25T21:47:45.230 回答