从base64 URI Phaser 3加载纹理图集

时间:2019-04-08 20:28:16

标签: javascript phaser-framework 2d-games texture-atlas

我正在使用Phaser 3开发一款游戏,该游戏将在基本的Chromium外壳内部署并运行。我无法在后台添加服务器来处理图像传送(并防止CORS问题),因此我正在使用here描述的方法将资产加载到游戏中。

我正在使用Webpack和url-loader为我的资产引入base64编码,并按如下方式加载它们:

import platformSrc from './images/platform.png';
import triggerSrc from './images/trigger.png';

然后,我正在使用preload()函数将它们添加到我的纹理管理器中。

preload() {
  const assetList = ['platform', 'trigger', 'audio', 'audioJson'];
  let nLoaded = 0; 

  this.cache.json.add('audioJson', audioJson);
  nLoaded++;

  this.textures.addBase64('platform', platformSrc);
  nLoaded++;
  this.textures.addBase64('trigger', triggerSrc);
  nLoaded++; 

  var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
  audioCtx.decodeAudioData(toArrayBuffer(audioSrc), (buffer) => {
    this.cache.audio.add('sfx', buffer);
    nLoaded++;
    if (nLoaded >= assetList.length) {
      var actualCreate = this.createGameObjects.bind(this);
      actualCreate();
    }
  }, (e) => { 
    console.log("Error with decoding audio data"); 
    nLoaded++;  
    if (nLoaded >= assetList.length) {
      var actualCreate = this.createGameObjects.bind(this);
      actualCreate();
    }
  });
}

所有这些工作。我的问题正在尝试使用此方法加载图集。我有一个atlas.pngatlas.json文件,其中包含一些打包的图像。我使用Leshy SpriteSheet Tool创建了此地图集,并以JSON-TP-Array格式导出。

我尝试像这样加载地图集:

this.load.atlas('atlas', atlasImg, atlasJson);

这:

this.textures.addAtlas('atlas', atlasImg, atlasJson);

还有:

this.textures.addBase64('atlasImg', atlasImg);
this.json.cache.add('atlasJson', atlasJson);
this.load.atlas('atlas', 'atlasImg', 'atlasJson');

全部无济于事。我不断收到此错误:

  

未捕获的TypeError:无法在执行'texImage2D'   'WebGLRenderingContext':未找到与   提供签名。

我一直在浏览TextureManager文档,试图找出我所缺少的内容,但似乎无法将它们放在一起。任何帮助是极大的赞赏。

0 个答案:

没有答案
相关问题