Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hidden undocumented functionality of CCLabelTTF's labelWithString:fontName:fontSize:dimensions: should be made explicit by creating a new factory method #883

Open
agro1986 opened this issue Jul 11, 2014 · 0 comments

Comments

@agro1986
Copy link

CCLabelTTF has a hidden functionality on its factory method, which is to make a label with a fixed width and then let the height be decided automatically by passing CGSizeMake(whatever, 0). That functionality should be made explicit by having this factory method:

+ (id) labelWithString:(NSString *)string fontName:(NSString *)name fontSize:(CGFloat)size width:(CGFloat)width
{
    return [[self alloc] initWithString:string fontName:name fontSize:size dimensions:CGSizeMake(width, 0)];
}

In the current Cocos2D 3.1, suppose someone has this string which they wants to display like movie credits, by having the text move up the screen:

descriptionText = @"Special thanks to wolverine, professor x,\
cyclops, wolverine, professor x, wolverine, professor x,\
wolverine, professor x, wolverine, professor x, wolverine,\
professor x, wolverine, professor x, jane";

They might first make it like this:

descriptionLabel = [CCLabelTTF labelWithString:descriptionText fontName:fontName fontSize:14.0f];

However it flows freely horizontally and no line break is introduced. So next they try this:

descriptionLabel = [CCLabelTTF labelWithString:descriptionText fontName:fontName fontSize:14.0f dimensions:dimension];

Great, now new line is inserted automatically (because a dimension is set). However, The text couldn't fit in the dimension so the bottom text are not displayed. So they add this line:

descriptionLabel.adjustsFontSizeToFit = YES;

However, now new lines aren't automatically inserted. Instead, all that one line is made to fit in the dimension resulting in text for ants.

What the user want is to make the width fixed (defined), but let the height be decided by the factory method. Currently there is no clear way to do it. It made me waste an hour, and my use case affects many people. I hope my suggestion is considered. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant