Hi
Does anyone know if BitmapFontAtlas can support multiline text, and if so how?
I know a single Label can do multiple lines by setting the dimensions of the label on creation, but I can't find anything similar for BitmapFontAtlas.
Cheers
A fast, easy to use, free, and community supported 2D game engine
Hi
Does anyone know if BitmapFontAtlas can support multiline text, and if so how?
I know a single Label can do multiple lines by setting the dimensions of the label on creation, but I can't find anything similar for BitmapFontAtlas.
Cheers
Hi,
BitmapFontAtlas as well as LabelAtlas don't support multiline text.
Edit:
try this tip by @LongJonnyE:
http://johnehartzog.com/2009/06/create-multi-line-labels-with-cocos-2d-iphone/
Here is the code, now that I learned how to use the backtick on these forums...
It basically just takes the hard-work out of creating multiple one-line labels by breaking up a string (but not in the middle of a word). Took a short time to create and debug, but hopefully I can save you the time!
I don't remember why I put a retain on the autoreleased BitmapFontAtlas objects. You might want to take them out and see if this code still works (it should?). If you don't release them at some other point, you are probably leaking that memory. Just FYI.
(void) setTipString:(NSString*)str {
NSInteger lineChars = 0;
BOOL isSpace = NO;
NSInteger index = 0;
NSInteger numLines = 0;
NSMutableString *line = [NSMutableString stringWithCapacity:LINE_LENGTH];
while (index <= [str length]) {
if(index == [str length]) {
BitmapFontAtlas *tip = [[BitmapFontAtlas bitmapFontAtlasWithString:[NSString stringWithString:line] fntFile:@"text.fnt" alignment:UITextAlignmentLeft] retain];
[tip setPosition: cpv(30,210 - 20 * numLines)];
[self addChild:tip];
return;
}
NSString *tmp = [str substringWithRange:NSMakeRange(index, 1)];
[line appendString:tmp];
if([tmp isEqual:@" "])
isSpace = YES;
else
isSpace = NO;
if(lineChars >= LINE_LENGTH && isSpace) {
BitmapFontAtlas *tip = [[BitmapFontAtlas bitmapFontAtlasWithString:[NSString stringWithString:line] fntFile:@"text.fnt" alignment:UITextAlignmentLeft] retain];
[tip setPosition: cpv(30,210 - 20 * numLines)];
[self addChild:tip];
lineChars = -1;
[line setString:@""];
numLines++;
}
lineChars++;
index++;
}
}Nice one, thanks for your help.
You must log in to post.