在cocos2d- x3中异步预加载精灵表并使用它
Preload spritsheet asynchronously in cocos2d-x 3 and use it
这是正确的预加载spritsheet异步,并在删除加载屏幕后在其他场景中适当地使用它吗?
// load the texture into the cache
Director::getInstance()->getTextureCache()->addImageAsync("ingame.png",
[](cocos2d::Texture2D *texture) {
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ingame.plist", texture);
// here remove loading screen and go to ingame scene to use the loaded spritesheet
}
);
// use the loaded spritesheet in ingame scene
auto bg = Sprite::createWithSpriteFrameName("ingame_bg.png");
bg->setPosition(origin + visibleSize / 2);
addChild(bg, 0);
据我所知,在调用addImageAsync
后,.png
文件被加载到GPU的内存中,但还没有关于精灵表中图像位置的信息。因此,我们也调用SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ingame.plist", texture);
来要求cocos2d-x解析.plist
文件并了解精灵表中的图像在哪里。这有意义吗?
如上所述,addSpriteFramesWithFile()
为您预加载。
查看来源:
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(texturePath.c_str());
if (texture)
{
addSpriteFramesWithDictionary(dict, texture);
_loadedFileNames->insert(pszPlist);
}
else
{
CCLOG("cocos2d: SpriteFrameCache: Couldn't load texture");
}
相关文章:
- std::原子加载和存储都需要吗
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 为什么加载SDF会导致Mobilizer创建闭环错误
- C++atioglxx.pdb未加载错误glBufferData OpenGL
- 如何使用tinyxml2从XML加载父实体和子实体
- 如何在C++中使用pybind11加载一个pickle python列表
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 当我尝试加载内核模块时,如何修复C++中的这个 malloc() 错误?
- 树莓上的 Libtorch 无法加载 pt 文件,但在 ubuntu 上工作
- Python ctypes:不会按预期加载 dll
- 为什么会出现 gettnig 运行时错误:加载类型为"_Bit_type"(stl_bvector.h) 的空指针?
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 保存/加载大量短数组到二进制文件
- 使用 SDL2 和SDL_image C++加载图像
- COCOS2D-X:从另一个线程中加载精灵,任何模式
- 通过循环加载精灵
- 在cocos2d- x3中异步预加载精灵表并使用它
- 如何加载精灵在intwithfile我使用cocos2d 2.2.0.4
- 是否有可能在程序执行过程中通过函数加载精灵、纹理和音乐?