Skip to content

Instantly share code, notes, and snippets.

@gear1554
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save gear1554/8969873 to your computer and use it in GitHub Desktop.

Select an option

Save gear1554/8969873 to your computer and use it in GitHub Desktop.
CCLabelAttributedBMFontの設定、使い方
// on "init" you need to initialize your instance
bool HelloWorld::init() {
//////////////////////////////
// 1. super init first
if (!CCLayer::init()) {
return false;
}
string str = "吾輩は猫である。名前はまだ無い。\nどこで生れたかとんと見当けんとうがつかぬ。\n何でも薄暗いじめじめした所で\nニャーニャー泣いていた事だけは\n記憶している。";
// create方法はCCLabelBMFontと同様でOK
CCLabelAttributedBMFont *attributeLabel = CCLabelAttributedBMFont::create(str.c_str(), "font.fnt");
attributeLabel->setAnchorPoint(ccp(0.0f, 1.0f));
attributeLabel->setPosition(ccp(0, CCDirector::sharedDirector()->getWinSize().height - 30));
// キーワードと対応する色、サイズを設定
attributeLabel->addKeyWord("猫", ccRED, 1.5f);
attributeLabel->addKeyWord("ニャーニャー", ccORANGE, 0.8f);
// 5フレームに1文字送る設定
attributeLabel->setDispCycle(5);
attributeLabel->setDispSpeed(1);
addChild(attributeLabel);
string strEn = "I am a cat.\nAs yet I have no name.\nI've no idea where I was born.\nI only remember that I cried 'meow meow' in a dark and damp.";
// create方法はCCLabelBMFontと同様でOK
CCLabelAttributedBMFont *attributeLabelEn = CCLabelAttributedBMFont::create(strEn.c_str(), "font.fnt");
attributeLabelEn->setAnchorPoint(ccp(0.0f, 1.0f));
attributeLabelEn->setPosition(ccp(0, CCDirector::sharedDirector()->getWinSize().height / 2));
// キーワードと対応する色、サイズを設定
attributeLabelEn->addKeyWord("cat", ccRED, 1.4f);
attributeLabelEn->addKeyWord("'meow meow'", ccORANGE, 0.8f);
// 1フレームに2文字送る設定
attributeLabelEn->setDispCycle(1);
attributeLabelEn->setDispSpeed(2);
addChild(attributeLabelEn);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment