如何将 PIXI.js 无需 运行 即可访问的图像托管到 CORS 问题中?

How to host image that can be accessed by PIXI.js without running into CORS issue?

我一直在使用 PIXI.js 创建一个基本游戏。当我尝试在远程位置玩游戏时,我 运行 遇到基于 CORS 的问题:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the
remote resource at http://example.com/myimage.png.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

我已经尝试通过在外部和本地计算机上托管图像来实现这一点。

作为解决方法,我一直在尝试使用 PIXI 库通过 javascript 创建我的图像,但我还没有找到从绘制的图形创建精灵的方法。 在 PIXI.js 上使用不会 运行 出现 CORS 相关问题的最佳托管图像的最佳方式是什么?

我相信您需要使用渲染器中的 .generateTexture 方法: http://pixijs.download/dev/docs/PIXI.Renderer.html#generateTexture

如果您是这样创建应用程序的:var app = new PIXI.Application() 您的渲染器将位于 app.renderer
所以像这样:

var redSquare = new PIXI.Graphics();
redSquare.beginFill(0xffffff);
redSquare.drawRect(50,50,100,100);
redSquare.endFill();
var red = new PIXI.Sprite(app.renderer.generateTexture(redSquare));