如何使用cocos2d-x v3.2在全局类(helloworld.h)中声明标签?

我用cocos2d-x v3.2(c ++)创建了一个2D平台游戏,我正在使用标签。

cocos2d-x v3.0(c ++)声明类似于cocos2d::LabelTTF* currentScore;

cocos2d-x v2.2.2(c ++)声明为cocos2d::CCLabelTTF* currentScore;

cocos2d-x v3.2(c ++)如何在全局类(helloworld.h)中声明标签我试过像

HelloWorld.h

 class HelloWorld : public cocos2d::LayerColor { public: virtual bool init(); cocos2d::LabelTTF* currentScore; //semantic issue(LabelTTF deprecared) }; #endif 

HelloWorld.cpp

 bool HelloWorld::init() { currentScore = LabelTTF::create("", "Arial", 40); //semantic issue(LabelTTF deprecared) // position the label on the center of the screen currentScore->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - currentScore->getContentSize().height)); // add the label as a child to this layer this->addChild(currentScore, 1); char buffer[10]; sprintf(buffer, "%04i",0); currentScore->setString(std::string(buffer)); } 

再试一次

HelloWorld.cpp

  bool HelloWorld::init() { Auto currentScore = LabelTTF::create("", "Arial", 40); //position the label on the center of the screen currentScore->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - currentScore->getContentSize().height)); // add the label as a child to this layer this->addChild(currentScore, 1); } #endif 

它工作但不能“自动当前分数”; 在全局类(HelloWorld.h)中声明

在.h文件中

 Label *autolabel4; 

在.cpp

// autolabel4 = Label :: create(); 无法改善标签尺寸和数量

 autolabel4 = Label::createWithSystemFont("hello","Arial.ttf",40); autolabel4->setString("name isss :"); autolabel4->setColor(Color3B(23,33,44)); autolabel4->setPosition(Point(origin.x+ visibleSize.width/2, origin.y + visibleSize.height - 400)); this->addChild(autolabel4, 1); 
Interesting Posts