Cocos2dx Text Outline
Here is sample code for text runtime creation with outline attribute.
Code implementation is simple, just check below code.
enableOutline attribute has input as Color4B with outline size. so you can set any color in Color4B. for example, if you want to set red color, just use pre-define Color4B::RED or put RGB color directly Color4B(255,0,0,255). forth value is Alpha code which is opacity. Important thing is that you must set outline size, if you forgot to set it, default value is 1.
auto msg = Text::create();
msg->setFontName("font/kenpixel.ttf");
msg->setFontSize(30);
msg->enableOutline(Color4B::RED, 3);
msg->setString("Font creation");
msg->setPosition(Vec2(100, 100);
this->addChild(msg);
That's it. very simple.
Here is addition code what I used text outline effect for new game app. This sample code is that show text when player get item with different type of color.
void GameScene::showText(const int &iType, const Vec2 &iAt, const std::string &iMsg)
{
auto msg = Text::create();
msg->setFontName("font/kenpixel.ttf");
msg->setFontSize(30);
if(iType == ITEM_HP)
msg->enableOutline(Color4B::RED, 3);
else if(iType == ITEM_THROW)
msg->enableOutline(Color4B(80, 51,29, 255), 3);
else if(iType == ITEM_SCORE)
msg->enableOutline(Color4B(150, 100, 60, 255), 3);
else if(iType == ITEM_KEY)
msg->enableOutline(Color4B(230, 196, 0, 255), 3);
msg->setString(iMsg);
msg->setPosition(iAt);
msg->runAction(Sequence::create(FadeIn::create(0.1f), MoveBy::create(0.3f, Vec2(0, 30)), FadeOut::create(0.1f), RemoveSelf::create(), NULL));
_pTileMap->addChild(msg);
}
Check video, implemented code will working like this.
|
'English > Programming Tips' 카테고리의 다른 글
Android vibrate method in Unity Enviroment (0) | 2017.07.02 |
---|---|
Best CC0 sprites for mobile developer (0) | 2017.01.24 |
How to play cocos studio sprite animation (ActionTimeLine) (0) | 2016.11.04 |
Call android Toast methon in cocos2dx by using JNI function (C++) (0) | 2016.11.03 |
How to use pugixml in android cocos2d develop enviroment (pugixml singleton / pugixml local path) (0) | 2016.10.05 |
How to set pugi xml in android cocos2d develop enviroment (0) | 2016.10.05 |
kingdom rush frontiers stage 10 get 3 stars (0) | 2016.10.04 |
최근댓글