Label Can't show stroke(outline) in Coco2dx 3.0 RC0

    auto testLabel = Label::create("TestLabelStroke", "HelveticaNeue-Bold", 40);
    testLabel->setPosition(Point(200, 200));
    testLabel->enableOutline(Color4B::BLUE, 1);
    this->addChild(testLabel, 100);

It don’t show “blue” stroke…

Only white…

Anyone have this issue??

Image Title
Image Title


enableOutline.png (11.4 KB)


normal.png (10.4 KB)

    auto testLabel = Label::create("TestLabelStroke", "Helvetica Neue Bold.ttf", 40);
    testLabel->setPosition(Point(200, 200));
    testLabel->enableOutline(Color4B::BLUE, 1);
    this->addChild(testLabel, 100);

Tried this code, the result was… surprising. I thought it would solved your issue, well it did, but also discovered a glitch.
Image Title
Image Title

@jonah1nine

Thanks your reply

“No file found at Helvetica Neue Bold.ttf. Possible missing file.”

It show some warning and no blue stroke at my ios device.

@Yehsam You have to have the font file inside your Resources folder.

But the first code work correct on Android device.

So… If i need use Label Outline, we need put font file inside my Resources folder on iOS device?

Why can’t use system font file?

Thanks a lot

@Yehsam I have not tested it with mobile devices, I’m testing the code under VS2012. I am not sure about using system font file, I always assume that fonts used should be in Resources. Maybe the devs can confirm this. Nonetheless, I’ve done further testing and maybe one of the code will work out for you. Best thing to do is to test them yourself and find what’s best for your project.

	auto fontFile = FileUtils::getInstance()->fullPathForFilename("fonts/Helvetica Neue Bold.ttf");

	auto testLabel = Label::create("TestLabelStroke", fontFile, 40); //font is under Resources/fonts
    testLabel->setPosition(Point(200, 200));
    testLabel->enableOutline(Color4B::BLUE, 1);
    this->addChild(testLabel, 100);

	auto testLabel0 = Label::create("TestLabelStroke0", "Helvetica Neue Bold.ttf", 40); //font is under Resources
    testLabel0->setPosition(Point(200, 250));
    testLabel0->enableOutline(Color4B::BLUE, 1);
    this->addChild(testLabel0, 100);

	auto testLabel1 = Label::create("TestLabelStroke1", "Times New Roman", 40); //system font
    testLabel1->setPosition(Point(200, 300));
    testLabel1->enableOutline(Color4B::BLUE, 1);
    this->addChild(testLabel1, 100);

	//Label::createWithTTF is deprecated
	auto testLabel2 = Label::createWithTTF("TestLabelStroke2", "Helvetica Neue Bold.ttf", 40); //font is under Resources
    testLabel2->setPosition(Point(200, 350));
    testLabel2->enableOutline(Color4B::BLUE, 1);
    this->addChild(testLabel2, 100);

	auto testLabel3 = LabelTTF::create("TestLabelStroke3", "Helvetica Neue Bold.ttf", 40); //font is under Resources
    testLabel3->setPosition(Point(200, 420));
	testLabel3->enableStroke(Color3B::BLUE, 1.f);
    this->addChild(testLabel3, 100);

Hope this helps.

@jonah1nine

Are your mobile device is Android??

I have test on my Android device, it work correct.

But not working on my iOS device.

Thanks a lot

@Yehsam

Here is a code compare for you .

you need down the font

http://59.51.114.6/file/MDAwMDAwMDF1FJZKeKnjtcvvf0_zRepj8GqT6h7VNWS68XDaoHDUzA../baddea286e2ef7b94581b2b5447cf83e8ab3a0/HelveticaNeue-Bold.ttf?key=AAABQFMrwMVpx6L4&p=&a=1971988-782a2efb-48049-0/010100&mode=download

put it under your Resource folder. and add it to you project

   auto testLabel1 = Label::create("TestLabelStroke", "HelveticaNeue-Bold", 40);
    testLabel1->setPosition(Point(200, 200));
    testLabel1->enableOutline(Color4B::BLUE, 1);
    this->addChild(testLabel1, 100);
    auto testLabel2 = Label::create("TestLabelStroke", "HelveticaNeue-Bold.ttf", 40);
    testLabel2->setPosition(Point(200, 100));
    testLabel2->enableOutline(Color4B::BLUE, 1);
    this->addChild(testLabel2, 100);

Thanks a lot all.

I think this is a issue on iOS 7 device

http://www.cocos2d-iphone.org/forums/topic/cclabelttf-stroke-not-working-in-ios-7/

It could fix at CCDevice.mm line 435

        if ( info->hasStroke )
        {
            CGContextSetTextDrawingMode(context, kCGTextStroke);
            
            if([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)
            {
                NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
                paragraphStyle.alignment = (NSTextAlignment)testAlign;
                paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
                [str drawInRect:rect withAttributes:@{
                                                      NSFontAttributeName: font,
                                                      NSStrokeWidthAttributeName: [NSNumber numberWithFloat:-info->strokeSize * 2],
                                                      NSForegroundColorAttributeName:[UIColor colorWithRed:info->tintColorR
                                                                                                     green:info->tintColorG
                                                                                                      blue:info->tintColorB
                                                                                                     alpha:1.0f],
                                                      NSParagraphStyleAttributeName:paragraphStyle,
                                                      NSStrokeColorAttributeName: [UIColor colorWithRed:info->strokeColorR
                                                                                                  green:info->strokeColorG
                                                                                                   blue:info->strokeColorB
                                                                                                  alpha:1.0f]}
                 ];
            }
            else
            {
                
                //original code that was not working in iOS 7
                [str drawInRect: rect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)testAlign];
            }
        }
        else
            [str drawInRect: rect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)testAlign];

Anyone can send pull request?

I don’t know how to use that!!

Thanks a lot

@Yehsam A ticket was created at http://cocos2d-x.org/issues/4444.
Master branch:Fixed at https://github.com/cocos2d/cocos2d-x/pull/5863

We will fixed it on develop branch ASAP.