逃跑的小猪 2016-09-27 09:44 采纳率: 0%
浏览 1794
已结题

cocos json 生成动画帧

//
/
//
//

#include "FlashTool.h"
#include

Animate * FlashTool::readJsonSpriteSheet(std::string jsonFile,float delayPerUnit){

rapidjson::Document doc;
std::string fileContent = FileUtils::getInstance()->getStringFromFile(jsonFile);
fileContent.erase(0,fileContent.find_first_of('{'));

doc.Parse<0>(fileContent.c_str());

std::string imgFileName = doc["meta"]["image"].GetString();

auto &frames = doc["frames"];
auto sfc = SpriteFrameCache::getInstance();

Vector<AnimationFrame*> animFrames;
for (auto m=frames.MemberBegin(); m!=frames.MemberEnd(); m++) {
    auto frameName = m->name.GetString();
    auto & frameProperties = m->value["frame"];
    auto & spriteSourceSize = m->value["spriteSourceSize"];

    auto sf = sfc->getSpriteFrameByName(frameName);
    if (!sf) {
        sf = SpriteFrame::create(imgFileName, Rect(frameProperties["x"].GetInt(), frameProperties["y"].GetInt(), frameProperties["w"].GetInt(), frameProperties["h"].GetInt()), m->value["rotated"].GetBool(), Vec2(spriteSourceSize["x"].GetInt(), spriteSourceSize["y"].GetInt()), Size(spriteSourceSize["w"].GetInt(), spriteSourceSize["h"].GetInt()));
        sfc->addSpriteFrame(sf, frameName);
    }
    animFrames.pushBack(AnimationFrame::create(sf, delayPerUnit, ValueMapNull));
}

Animation * animation = Animation::create(animFrames,delayPerUnit);
return Animate::create(animation);

}

解析json 文件 生成动画,让一个sprite执行动作,
auto b1 = Sprite::create();
auto dd = RepeatForever::create(FlashTool::readJsonSpriteSheet("Hero.json", 0.3f));
b1->runAction(dd);
在电脑上能显示,打包到android手机上不显示动画,
哪位大神能帮帮忙,感谢,感谢

  • 写回答

1条回答 默认 最新

  • devmiao 2016-09-27 16:52
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛