Hello I am making a side scrolling cocos2d game and I want a label to show how far the user has flown in the game. For some reason with the code I wrote the label is not appearing. Here is my GameEngine class that calls the class method that is supposed to make the label appear:
//Set the meterDistance
meterDistance = [MeterDistance createTheMeterDistance];
[self addChild:meterDistance z:10];
Here is the code in the MeterDistance class:
meters = 1;
meterLabel = [CCLabelBMFont labelWithString:@"0" fntFile:@"green_arcade-ipad.fnt"];
meterLabel.position = ccp(200, screenHeight - 100);
[self addChild:meterLabel z:10];
meterLabel.anchorPoint = ccp(1.0, 0.5);
[self schedule:@selector(updateLabel:)interval:1.0f/20.0f];
Here is the updateLabel method:
-(void)updateLabel:(ccTime)delta{
meters++;
NSString* scoreString = [NSString stringWithFormat:@"%d", meters];
[meterLabel setString:scoreString];
}
It's been a while since I last dealt with cocos2d code... What you've written looks ok.
Take it one step at a time and see where it goes wrong. Position your label in the middle of the screen (maybe screenheight is off, or anchorPoint moves the label outside of the screen).
Another possible cause is if the font file name is not exactly @"green_arcade-ipad.fnt". Maybe you missed a capital letter?
Otherwise maybe some other element of your layer could be obstructing the label.