如何使用 Cocos2D-X v3.2 在全局类 (Helloworld.h) 中声明标签
how to declare label in global class (helloworld.h) with cocos2d-x v3.2?
我正在使用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(我试过像
你好世界
class HelloWorld : public cocos2d::LayerColor
{
public:
virtual bool init();
cocos2d::LabelTTF* currentScore; //semantic issue(LabelTTF deprecared)
};
#endif
你好世界.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));
}
再试一次
你好世界.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);
相关文章:
- C 和 C++ 中开关语句的案例标签的常量值,但显示不同的行为
- 如何正确指定 goto 语句的标签?
- 使用g++静态初始化带有命名标签的嵌套C++结构
- 在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题
- 构建失败错误:无法使用 qibuild 构建C++ SDK Helloworld
- 通过水平滚动条更改标签
- 从 QFontDatabase 设置 QFont 将所有标签设置为等宽字体?Qt C++
- 在C++中存储要输入的标签列表
- 如何在等效列表中查找最小的连接标签
- 标签检测鼠标单击 c++
- 无法将行编辑中的文本打印到 Qt C++ 中的标签
- 如何根据C++中的标签运行特定函数?
- C++ Expat 仅打印元素的第一个字母和标签中的数据
- 默认标签显然在 switch 语句中不起作用
- 在 gcc/clang (C++) 中获取函数范围之外的标签地址
- 在"printf"中使用标签"h"或"hh"是否涉及未定义的
- GTK 3 C++按钮中带有标签的图标
- 我可以在不创建项目的情况下在Visual Studio 2019中编译和运行HelloWorld.cpp吗?
- 如何使QLineSeries/QXYSeries仅显示一个点标签
- 如何使用 Cocos2D-X v3.2 在全局类 (Helloworld.h) 中声明标签