mirror of https://github.com/axmolengine/axmol.git
new CCLabelTTF (static) create with fontDefinition method, and new CPP test using it
This commit is contained in:
parent
1a5de55d39
commit
494ec43fe8
|
@ -96,6 +96,18 @@ CCLabelTTF* CCLabelTTF::create(const char *string, const char *fontName, float f
|
|||
return NULL;
|
||||
}
|
||||
|
||||
CCLabelTTF * CCLabelTTF::createWithFontDefinition(const char *string, ccFontDefinition &textDefinition)
|
||||
{
|
||||
CCLabelTTF *pRet = new CCLabelTTF();
|
||||
if(pRet && pRet->initWithStringAndTextDefinition(string, textDefinition))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CCLabelTTF::init()
|
||||
{
|
||||
return this->initWithString("", "Helvetica", 12);
|
||||
|
|
|
@ -70,6 +70,10 @@ public:
|
|||
const CCSize& dimensions, CCTextAlignment hAlignment,
|
||||
CCVerticalTextAlignment vAlignment);
|
||||
|
||||
|
||||
/** Create a lable with string and a font definition*/
|
||||
static CCLabelTTF * createWithFontDefinition(const char *string, ccFontDefinition &textDefinition);
|
||||
|
||||
/** initializes the CCLabelTTF with a font name and font size */
|
||||
bool initWithString(const char *string, const char *fontName, float fontSize);
|
||||
|
||||
|
|
|
@ -1479,9 +1479,6 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
|
|||
|
||||
CCSize shadowOffset(12.0, 12.0);
|
||||
|
||||
// create the label shadow only
|
||||
CCLabelTTF* fontShadow = new CCLabelTTF();
|
||||
|
||||
ccFontDefinition shadowTextDef;
|
||||
shadowTextDef.m_fontSize = 20;
|
||||
shadowTextDef.m_fontName = std::string("Marker Felt");
|
||||
|
@ -1492,7 +1489,8 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
|
|||
shadowTextDef.m_shadow.m_shadowBlur = 1.0;
|
||||
shadowTextDef.m_fontFillColor = tintColorRed;
|
||||
|
||||
fontShadow->initWithStringAndTextDefinition("Shadow Only Red Text", shadowTextDef);
|
||||
// shadow only label
|
||||
CCLabelTTF* fontShadow = CCLabelTTF::createWithFontDefinition("Shadow Only Red Text", shadowTextDef);
|
||||
|
||||
// add label to the scene
|
||||
this->addChild(fontShadow);
|
||||
|
@ -1500,9 +1498,7 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
|
|||
|
||||
|
||||
|
||||
// create the label stroke only
|
||||
CCLabelTTF* fontStroke = new CCLabelTTF();
|
||||
|
||||
// create the stroke only label
|
||||
ccFontDefinition strokeTextDef;
|
||||
strokeTextDef.m_fontSize = 20;
|
||||
strokeTextDef.m_fontName = std::string("Marker Felt");
|
||||
|
@ -1513,7 +1509,8 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
|
|||
|
||||
strokeTextDef.m_fontFillColor = tintColorYellow;
|
||||
|
||||
fontStroke->initWithStringAndTextDefinition("Stroke Only Yellow Text", strokeTextDef);
|
||||
// stroke only label
|
||||
CCLabelTTF* fontStroke = CCLabelTTF::createWithFontDefinition("Stroke Only Yellow Text", strokeTextDef);
|
||||
|
||||
// add label to the scene
|
||||
this->addChild(fontStroke);
|
||||
|
@ -1522,8 +1519,6 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
|
|||
|
||||
|
||||
// create the label stroke and shadow
|
||||
CCLabelTTF* fontStrokeAndShadow = new CCLabelTTF();
|
||||
|
||||
ccFontDefinition strokeShaodwTextDef;
|
||||
strokeShaodwTextDef.m_fontSize = 20;
|
||||
strokeShaodwTextDef.m_fontName = std::string("Marker Felt");
|
||||
|
@ -1540,12 +1535,15 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
|
|||
|
||||
strokeShaodwTextDef.m_fontFillColor = tintColorBlue;
|
||||
|
||||
fontStrokeAndShadow->initWithStringAndTextDefinition("Stroke & Shadow Blue Text", strokeShaodwTextDef);
|
||||
// shadow + stroke label
|
||||
CCLabelTTF* fontStrokeAndShadow = CCLabelTTF::createWithFontDefinition("Stroke & Shadow Blue Text", strokeShaodwTextDef);
|
||||
|
||||
// add label to the scene
|
||||
this->addChild(fontStrokeAndShadow);
|
||||
fontStrokeAndShadow->setPosition(ccp(s.width/2,s.height/4*1.1));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::string TTFFontShadowAndStroke::title()
|
||||
|
|
Loading…
Reference in New Issue