Game Development Reference
In-Depth Information
Add the code in
Listing 11-18
just below the code fragment of
Listing 11-17
.
There may
already be a
didLoadFromCCB
method in the class. If there is, you should replace it
with the one in
Listing 11-18
.
Listing 11-18
.
Initializing the format string and updating it once
-(void) didLoadFromCCB
{
_hitsLocalizedFormatString = _hitsLabel.string;
[self updateHitsLabel];
}
-(void) updateHitsLabel
{
if (_hitsLabel)
{
_hitsLabel.string = [NSString stringWithFormat:
_hitsLocalizedFormatString,
_hitCount];
}
}
The
_hitsLocalizedFormatString
will be set to either “Hits: %i” or “Treffer:
%i” depending on the system language. The
updateHitsLabel
method then uses the
_hitsLocalizedFormatString
as the format string in
NSString
's
stringWithFormat
method. The
_hitCount
variable provides the value that %i
should be replaced with. So after the CCB is loaded, the bitmap font's label string will be
either “Hits: 0” or “Treffer: 0”, depending on the language.
want to update the hit-count label, you can call that method and it will increase the
_hitCount
variable before updating the label's string.
Listing 11-19
.
Increasing the hit-count label
-(void) increaseHitCount
{
_hitCount++;
[self updateHitsLabel];
}
Search WWH ::
Custom Search