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
2107fdddf1
commit
b7ffb5b810
|
@ -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);
|
||||
|
||||
|
|
|
@ -1506,9 +1506,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");
|
||||
|
@ -1519,7 +1516,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);
|
||||
|
@ -1527,9 +1525,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");
|
||||
|
@ -1540,7 +1536,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);
|
||||
|
@ -1549,8 +1546,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");
|
||||
|
@ -1567,12 +1562,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