gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:02:41 24 4
gpt4 key购买 nike

我正在使用 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)中声明标签我试过了

Hello World .h

class HelloWorld : public cocos2d::LayerColor

{
public:
virtual bool init();
cocos2d::LabelTTF* currentScore; //semantic issue(LabelTTF deprecared)
};

#endif

Hello World .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));
}

再试一次

Hello World .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

它工作但不能“Auto currentScore;”在全局类(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);

关于c++ - 如何使用cocos2d-x v3.2 在全局类(helloworld.h) 中声明标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27577619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com