博客
关于我
【前端/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/

    你可能感兴趣的文章
    PowerDesigner逆向工程从SqlServer数据库生成PDM(图文教程)
    查看>>
    PowerEdge T630服务器安装机器学习环境(Ubuntu18.04、Nvidia 1080Ti驱动、CUDA及CUDNN安装)
    查看>>
    PowerPC-object与elf中的符号引用
    查看>>
    QFileSystemModel
    查看>>
    Powershell DSC 5.0 - 参数,证书加密账号,以及安装顺序
    查看>>
    PowerShell 批量签入SharePoint Document Library中的文件
    查看>>
    Powershell 自定义对象小技巧
    查看>>
    pytorch从预训练权重加载完全相同的层
    查看>>
    PowerShell~发布你的mvc网站
    查看>>
    PowerShell使用详解
    查看>>
    Powershell制作Windows安装U盘
    查看>>
    powershell命令
    查看>>
    Powershell如何查看本地公网IP
    查看>>
    pytorch从csv加载自定义数据模板
    查看>>
    powershell对txt文件的服务器进行ping操作
    查看>>
    powershell常用
    查看>>
    PowerShell操作XML遇到的问题
    查看>>
    PowerShell攻击工具Empire实战
    查看>>
    PowerShell攻击工具Nishang实战
    查看>>
    PowerShell攻击工具PowerSploit实战
    查看>>