博客
关于我
【前端/Spine.js】不使用服务器形式来传递json和altas数据
阅读量:147 次
发布时间:2019-02-28

本文共 1196 字,大约阅读时间需要 3 分钟。

技术说明

使用AssetManager类加载数据与图片

测试环境

  • 浏览器:Chrome 81.0.4
  • 工具:Visual Studio Code

代码实现

AssetManager类新增方法

AssetManager.prototype.loadTextData = function(path, data) {    var _this = this;    path = this.pathPrefix + path;    this.toLoad++;    _this.assets[path] = data;    _this.toLoad--;    _this.loaded++;};

图片数据处理

AssetManager.prototype.loadTextureData = function(path, data, success, error) {    var _this = this;    path = this.pathPrefix + path;    this.toLoad++;    var img = new Image();    img.onload = function(ev) {        var texture = _this.textureLoader(img);        _this.assets[path] = texture;        _this.toLoad--;        _this.loaded++;        if (success) success(path, img);    };    img.onerror = function(ev) {        _this.errors[path] = "Couldn't load image " + path;        _this.toLoad--;        _this.loaded++;        if (error) error(path, "Couldn't load image " + path);    };    img.src = data;};

实例说明

将atlas数据存储到JS代码中

  • 打开.atlas文件
  • 使用正则表达式提取数据
  • 替换<div>标签为\,并替换\n
  • 复制并粘贴到JS文件中,去掉最后的\
  • 将JSON数据存储到JS代码中

  • 安装PrettifyJSON扩展
  • 打开对应的.json文件
  • 使用快捷键全选并复制到JS文件中
  • 将PNG数据存储到JS代码中

  • 使用在线转换工具将PNG转换为Base64
  • 复制Base64代码并粘贴到JS文件中
  • 示例代码

    // 示例代码

    以上内容详细描述了如何使用AssetManager类加载不同类型的数据,包括文本和图片,并提供了具体的使用方法和示例代码。

    转载地址:http://byxc.baihongyu.com/

    你可能感兴趣的文章
    Python 写Android App性能:入门到高级
    查看>>
    python 写入json数据到数据库
    查看>>
    Python 出现 TypeError: ‘encoding‘ is an invalid keyword argument for this function 解决方法
    查看>>
    python 出现 TypeError: ‘list‘ object is not callable 的解决方法
    查看>>
    python 函数1
    查看>>
    python 函数学习
    查看>>
    Python 函数随笔 map()函数,lambda自定义函数
    查看>>
    Python 分析天气,告诉你中秋应该去哪里
    查看>>
    python 列表中dict中key排序
    查看>>
    python 列表函数
    查看>>
    Python 列表删除相同的元素
    查看>>
    python 列表生成式
    查看>>
    Python 列表解析 大文件
    查看>>
    python 列表转字典方法
    查看>>
    Python 列表(List)概述-ChatGPT4o作答
    查看>>
    Python网络爬虫基础进阶到实战教程
    查看>>
    Python 初学者需要知道的四条建议
    查看>>
    Python 判断字符串是否包含子字符串
    查看>>
    python 判断当前时间是否为零点
    查看>>
    python 利用pandas读取本地中CSV文件的指定列 列名重命名 并保存回本地
    查看>>