Hey Bobby, I private messaged you back. Can you confirm that you are running the latest version on https://github.com/pingpongboss/CCLabelBMFontMultiline
Multiline CCLabelBMFont bug
(41 posts) (16 voices)-
Posted 6 months ago #
-
Hi Mark,
Thanks for the message. Think I've sorted it now.
Yes I was using latest from your github. The problem was that I was reading in from a text document and writing out to the screen of my program (actually I was generating a plist from resources in a text file which I then used as a resource for the program but the intermediate stage isn't relevent here). The problem only occurred when it encountered a LF NL in the text, i.e. ASCII 0D 0A. When it encountered that combination the following text no longer wordwrapped. I have solved this by adding this line to my input text cleaning function:
inputString = [inputString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"];
Everything now works fine.
Thanks for your work on the utility really useful.
One other thing - when you do centre or right justified, it only seem to centre or right place the text box, and not the text within the box, so still looks left justified within the box. Is that correct or am I causing some more strange behaviour with some control characters?
Bobby
Posted 6 months ago # -
Hi Bobby,
I'm not an expert on text control characters. I only assumed the input text would contain '\n' since I have no idea really what the other control chars do.
Right justified is supposed to look like this:

You can download the entire Xcode project from my github and run the test app. The correct behavior should be there. Then you could put your own string into the example sentences and verify what it is that messes the justification up.Posted 6 months ago # -
Thanks. I'm sure I can get to the bottom of it now.
Posted 6 months ago # -
Mark,
I've had more of a look into this and I've got some test cases that produce strange results with a combination of \n newlines and space characters. The test code is:
CCLabelBMFont* textLabel; textLabel = [CCLabelBMFont labelWithString:@"Text with centre alignment and \nnewline characters \nto deal with" fntFile:@"WITWFont.fnt" width:600 alignment:UITextAlignmentCenter]; textLabel.position = ccp(368,950); [self addChild:textLabel z:100]; textLabel = [CCLabelBMFont labelWithString:@"Text with centre alignment and \nnewline characters\nto deal with" fntFile:@"WITWFont.fnt" width:600 alignment:UITextAlignmentCenter]; textLabel.position = ccp(368,750); [self addChild:textLabel z:100]; textLabel = [CCLabelBMFont labelWithString:@"Text with centre alignment and\nnewline characters \nto deal with" fntFile:@"WITWFont.fnt" width:600 alignment:UITextAlignmentCenter]; textLabel.position = ccp(368,550); [self addChild:textLabel z:100]; textLabel = [CCLabelBMFont labelWithString:@"Text with centre alignment and\nnewline characters\nto deal with" fntFile:@"WITWFont.fnt" width:600 alignment:UITextAlignmentCenter]; textLabel.position = ccp(368,350); [self addChild:textLabel z:100]; textLabel = [CCLabelBMFont labelWithString:@"Text with centre alignment and\n\nnewline characters\n\nto deal with" fntFile:@"WITWFont.fnt" width:600 alignment:UITextAlignmentCenter]; textLabel.position = ccp(368,150); [self addChild:textLabel z:100];Below may be a screenshot of the results (I'm not quite sure how to attach a file so may not work, but run the code above to see)
/Users/bobbygilbert/Desktop/Screen shot 2011-11-30 at 09.04.44.pngNotice that the only correct one is if there are no spaces in front of the \n character. Note that in the last example where I have double newlines \n\n it removes some characters from the end of the string.
Regards
Bobby
Posted 5 months ago # -
PS Can anyone tell me how to add the screenshot to my post? Obviously didn't work in previous mail.
Posted 5 months ago # -
Another example:
CCLabelBMFont* textLabel; textLabel = [CCLabelBMFont labelWithString:@"Text with no leading spaces which is quite long and so should wrap. All lines correctly line up to the left" fntFile:@"WITWFont.fnt" width:600 alignment:UITextAlignmentLeft]; textLabel.position = ccp(300,800); [self addChild:textLabel z:100]; textLabel = [CCLabelBMFont labelWithString:@" Text with leading spaces. This is also long and should wrap. I want to see an indent on the first line, like in most books, but it still all lines up" fntFile:@"WITWFont.fnt" width:600 alignment:UITextAlignmentLeft]; textLabel.position = ccp(300,600); [self addChild:textLabel z:100];Bobby
Posted 5 months ago # -
If anyone is interested, I found a workaround for the last issue (leading spaces) which is to insert an unrecognised character at the beginning of the line. As long as it isn't in your .fnt file it won't be printed, but magically the leading spaces do then appear. I found this useful for printing out text where each para needs to start with an indented line.
Anyone tried out the problems with the \n newline characters? My workaround is to check that they are never preceded by spaces. Would be great to have a more robust solution though.
Bobby
Posted 5 months ago # -
Thanks Bobby! It's finals time for UC Berkeley so i wont be able to work on this for a while.
Posted 5 months ago # -
>> Note that in the last example where I have double newlines \n\n it removes some characters from the end of the string.
I've run into this as well.
Bobby, to put images in the posts, just use HTML img tags:
<img src="http://blahblahblah.com/blah.jpg">Posted 5 months ago # -
Good luck with the finals Mark. Let me know if/when you get around to this. As I said, I've got workarounds for now so no rush.
Bobby
Posted 5 months ago #
Reply
You must log in to post.