Cocos2d-x3.2文字表示
2229 ワード
GameScene.h
#include "cocos2d.h"
class GameScene : public cocos2d::Layer
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
void menuCallback(cocos2d::Ref* pSender);
CREATE_FUNC(GameScene);
};
GameScene.cpp
#include "GameScene.h"
USING_NS_CC;
cocos2d::Scene* GameScene::createScene()
{
auto scene = Scene::create(); //
auto layer = GameScene::create(); //
scene->addChild(layer);
return scene;
}
//
bool GameScene::init()
{
if(!Layer::init()) //
return false;
//
Size visibleSize = Director::getInstance()->getVisibleSize();
//auto size = Director::getInstance()->getWinSize();
//
//
auto label1 = Label::createWithSystemFont("Jacedy", "Consolas", 36);
label1->setPosition(Vec2(visibleSize.width*0.2, visibleSize.height*0.8));
label1->setColor(Color3B(255, 0, 0)); //
this->addChild(label1);
//
TTFConfig config("Marker Felt.ttf", 25);
auto label2 = Label::createWithTTF(config, "Jacedy");
label2->setPosition(Vec2(visibleSize.width*0.2, visibleSize.height*0.6));
label2->enableGlow(Color4B::BLUE); // , ttf
label2->enableOutline(Color4B(255, 0, 0, 255), 5); // , 5, ttf
this->addChild(label2);
// ( , )
auto label3 = Label::createWithBMFont("bitmapFontChinese.fnt", " ");
label3->setPosition(Vec2(visibleSize.width*0.2, visibleSize.height*0.4));
this->addChild(label3);
//
auto label4 = Label::createWithCharMap("tuffy_bold_italic-charmap.plist");
label4->setPosition(Vec2(visibleSize.width*0.6, visibleSize.height*0.8));
this->addChild(label4);
label4->setString("Jacedy");
//
auto label5 = Label::create("Jacedy", "Marker Felt", 50);
label5->setPosition(Vec2(visibleSize.width*0.6, visibleSize.height*0.6));
this->addChild(label5);
return true;
}
要点:まず、プロジェクトのResourceフォルダにリソースファイルをロードし、関数に「ファイル名(xxx.fnt)」と入力して、パス「fonts/」も入れないでください.そうしないと、エラーが発生します.