Adding scores to game using cocos2d-x -
I am making a game in cocos2d-x and I am trying to add scores to my game. First I declared a score variable and set the value to 0. While doing this, while using the loop I used the loop in the value of 1, and showed me the score using printf but it is not working. Please help me with some code.
Int Score; Socrates = 0 {printf ("% d", score); } While (score> = 0)
If you have your score graphically
- Make a
cocos2d :: Label
, see the documentation. - Set its value:
label-> setString (Std :: to_string (score));
-
addChild (label, 1);
In your layer code where it is understood. -
label-> Set-position (...)
There are several types of label types and constructors that you can use, look upwards Use:
This is a simple example using one of the consultants given here:
cocos2d :: LabelBMFont * label = cocos2d :: LabelBMFont :: create (std :: to_string) (Score), "marker imposed"); Label-> SetAlignment (Cocos2d :: TextHAlignment :: center); AddChild (label, 0); Label-> SetPosition (...);
When you need to update the score, as it changes, then do something like this:
_label-> setstring (std :: to_string (score));
Comments
Post a Comment