Hi dear developers! I’m just wrote my first iphone game. But i have faced an information output problem below
myStr = [NSString stringWithFormat:@"Best Score:", counter];
The variable “counter” each time changes value at hit in the enemy. But in the information output I receiving always a zero, like “Best Score: 0”. Help to understand and fix that problem.
Class Texture & Sprite I’ve got from John Ward from http://www.karmatoad.co.uk
Some code here:
myStr = [NSString stringWithFormat:@"Best Score:", counter];
_Texture = [[Texture alloc] initWithText: myStr fontSize:24];
_Sprite = [[Sprite alloc] initWithTexture: _Texture];
[_Sprite drawSprite];
As others have suggested, you are missing the placeholder for your variable. I just wanted to provide some background:
NSStringsupports the format characters defined for the ANSI C functionprintf(), plus%@for any object.In format strings, a
%character announces a placeholder for a value, with the characters that follow determining the kind of value expected and how to format it, i.e. format specifiers.