博客
关于我
【前端/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中DrissionPage的详细解析与实战
    查看>>
    python中enumerate、变量类型转换
    查看>>
    python中execute是啥_python – 为什么“c.execute(…)”打破循环?
    查看>>
    python中exit和break区别_Python中exit()和sys.exit()之间的区别
    查看>>
    python中h5的用法
    查看>>
    python中http协议编程_HTTP编程
    查看>>
    python中import os_Python:相对导入与绝对导入(import)、os.path、__file__
    查看>>
    python中is和==操作符
    查看>>
    Python中range对象的使用以及打印九九乘法表
    查看>>
    Python中set.discard和set.remove方法之间的运行时差异?
    查看>>
    python中tkinter中value_输入字段中的python Tkinter get()值
    查看>>
    Python中wx.FlexGridSizer
    查看>>
    Python中xPath技术和BeautifulSoup的使用
    查看>>
    python中yield的用法详解——最简单,最清晰的解释
    查看>>
    python中‘set.intersection()‘的算法是什么?
    查看>>
    Python中一个图形中的多个绘图
    查看>>
    python中一个好的持久同步队列
    查看>>
    Python中不准确的对数
    查看>>
    python中什么是实例方法_在Python中创建实例方法对象的不同方法
    查看>>
    Python中使用cutecharts实现简单的手绘风格的图表
    查看>>