2014-07-11

Fixing undesired outline of Label in cocos2d-x 3.0

Recently, when I work on my TDDLib project, I found that the Label of cocos2d-x 3.0 show the Label with an undesired outline which isn't I want to (The first label shown below).



After several google search, I found the solution to fix it (The second label shown above).

It's simple, just call the blend of the Label to BlendFunc::ALPHA_PREMULTIPLIED.
Code: label->setBlendFunc(BlendFunc::ALPHA_PREMULTIPLIED

Source example:
std::string sysFont = "GillSans";

std::string test1 = "No BlendFunc";
std::string test2 = "ALPHA_PREMULTIPLIED";

Label *label;
Color3B textColor = Color3B(200, 245, 245);

// First Label (Undesired outline)
label = Label::createWithSystemFont(test1, sysFont, 40);
label->setColor(textColor);
label->setPosition(Point(250, 300));
addChild(label);

// Second Label (Fixed outline)
label = Label::createWithSystemFont(test2, sysFont, 40);
label->setColor(textColor);
label->setPosition(Point(250, 200));
label->setBlendFunc(BlendFunc::ALPHA_PREMULTIPLIED);

addChild(label);











No comments:

Post a Comment