图层不会绘制另一个图层
Layer doesn't draw in another one
我正在尝试制作类似自定义消息框的东西,但 MB 层不想显示在主层(实际上是场景)上。我已经用 2 个文本框实现了非常基本的层 (cocos2d::Layer)。我通过以下方式将其添加到场景中
this->addChild(layer);
但实际上什么都没有出现。我已经通过音频引擎添加了音乐并播放,但我仍然在主场景中看不到任何东西。 Cocos2d-x版本是3.16(最新),我也在win32上使用最新的MSVC。
您需要在场景中添加一次图层作为子图层,然后在将精灵或其他节点添加到图层之后。例如创建从 cocos2d::Layer 继承的测试场景 HelloWorld:
class HelloWorld : public cocos2d::Layer
{
public:
static cocos2d::Scene* createScene();
//...
然后使用工厂方法将场景创建定义为:
Scene* HelloWorld::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
在 init 方法中,尝试将你的简单对象添加到继承自 cocos2d::Layer 的 HelloWorld 中,Layer 是 cocos2d::Scene 的子对象:
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
// position the label on the center of the screen
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, 1);
在所有这些步骤之后,导演运行了这个场景:
//...
// create a scene. it's an autorelease object
auto scene = HelloWorld::createScene();
// run
director->runWithScene(scene);
//...
相关文章:
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 运行同一解决方案的另一个项目的项目
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- C++从另一个类访问公共静态向量的正确方法是什么
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- 使用std::transform将一个范围的元素添加到另一个范围中
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- 修改函数中的指针(将另一个指针作为参数传递)
- 为什么我不能将一个对象push_back到属于另一个类的对象向量中?
- C++试图读取一个文件并输出到另一个文本文件
- 如何将指针从一个void函数传递到另一个C++
- 如何从另一个文件继承私有成员变量和公共函数
- 使用.find函数在c++中查找字符和另一个字符之间的大小
- 图层不会绘制另一个图层
- 在 caffe 中仅编译一个图层文件
- 从另一个桌面捕获屏幕截图
- 另一个从剪贴板线程绘制位图
- 从另一个HBITMAP复制一个位图