本文共 1637 字,大约阅读时间需要 5 分钟。
一、VS编译没错,移植到Eclipse时,遇到“Unable to execute dex: Multiple dex files define”
二、多分辨率适应。
参考:
http://www.erlangsir.com/2013/08/21/cocos2d-x%E5%A4%9A%E5%88%86%E8%BE%A8%E7%8E%87%E9%80%82%E9%85%8D%E6%96%B9%E6%A1%88%EF%BC%9Asetdesignresolutionsize%E4%BD%BF%E7%94%A8/
Cocos2dx官方默认:
glview->setDesignResolutionSize(435, 640, ResolutionPolicy::SHOW_ALL);目前只加了官方默认的这句,先这么用着,等界面完备时再调整。 三、关于.plist文件。
加载plist文件时,可以同时加载,但是.plist文件里拆分图片时,不同.plist名字不能一样,不然你就杯具去吧。
下面异步加载示例【单个文件】:
void LoadingScene::onEnter(){ auto size=Director::getInstance()->getVisibleSize(); //添加背景 auto splash=Sprite::create("load.png"); splash->setPosition(Point(size.width/2,size.height/2)); this->addChild(splash); //图片资源的异步加载 TextureCache::getInstance()->addImageAsync("ui/colorball.png",CC_CALLBACK_1(LoadingScene::loadComplete,this));}//图片加载完成后的回调函数void LoadingScene::loadComplete(Texture2D *texture){ //texture是加载完的图片资源 SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ui/colorball.plist",texture); log("load complete"); //界面切换 /*auto gameLayer=GameScene::create(); Director::getInstance()->replaceScene(TransitionRotoZoom::create(3.0f,gameLayer));*/ auto scene = MainScene::createScene(); Director::getInstance()->replaceScene(TransitionFade::create(3.0f, scene));}然后在.h里声明函数:
void onEnter() override; void loadComplete(Texture2D *texture);
加载多个:
//png加入全局cache中 SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ui/colorball.plist", "ui/colorball.png"); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ui/colorballPress.plist", "ui/colorballPress.png"); auto cache = SpriteFrameCache::getInstance();//共享的帧序列使用时,按设定名字使用即可。由于加载到一个cache里,所以重名就乱套了。
转载地址:http://tvnmb.baihongyu.com/