博客
关于我
【前端/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 | ggplot,一个超强的 Python 库!
    查看>>
    python | unoconv,一个超厉害的 Python 库!
    查看>>
    python | webassets,一个超强的 Python 库!
    查看>>
    python | werkzeug,一个不可思议的 Python 库!
    查看>>
    python | xlsxwriter,一个实用的 Python 库!
    查看>>
    python | xlwings,一个非常实用的 Excel 相关的 Python 库!
    查看>>
    python读取含中文的json
    查看>>
    python | 提升代码迭代速度的Python重载方法
    查看>>
    python | 深入理解Python并发编程中的GIL限制与解决方案
    查看>>
    Python | 爬虫实战——亚马逊搜索页监控(附详细源码)
    查看>>
    python | 高效使用Python工具自动生成模块文档的秘诀
    查看>>
    python 一个list去除另一个list中的值
    查看>>
    python 三大框架的 介绍。
    查看>>
    Python 下载的 11 种姿势,一种比一种高级!
    查看>>
    python读取一个文件夹下所有图片_初学Python-找出文件夹下的所有图片
    查看>>
    Python 中 3 个不可思议的返回功能
    查看>>
    python 中 dict 的另一种用法
    查看>>
    Python 中 PIL 读取图片出现异常旋转的解决方法
    查看>>
    Python 中只有一个 True 和一个 False 对象吗?
    查看>>
    python读取mtcars数据集并实现以下操作_关于数据处理。。,Python交流,技术交流区,鱼C论坛 - Powered by Discuz!...
    查看>>