The reason why your score is stuck at 11 is that at the first line of your function you set it to 1
. It seems that you wanted to pass current score as an argument to this function, but it won't work like this with your schedule.
Example code for adding 10 points with every call of updateScore
:
void HudLayer::updateScore() // no argument needed
{
//score=1; <- this would override current score, bug/not needed
do { // unnecessary
score=score+10;
const int labelLength = 100;
char scoreLabelText[labelLength];
snprintf(scoreLabelText, labelLength, "Score: %d", score);
scoreLabel->setString(scoreLabelText);
} while (score<0); //unnecessary
}
// in your *.h file
class HudLayer : <your inheritance> {
int score;
//your code
}
Of course you should initialize the score
to some value, but do it only once, for example in the constructor or init()
method.
Let me know if anything is not clear.