跨源安全性错误

时间:2016-07-02 05:43:38

标签: javascript jquery html5-canvas cross-domain webgl

我试图制作一个允许玩家为本地浏览器上显示的玩家提供自定义天赋的用户脚本。在游戏中返回天赋纹理的函数使得画布能够获得包含所有元素的天赋图像的正确部分,然后制作出PIXI纹理。每当我尝试将自己的PIXI纹理分配给播放器时,其来源是imgur上的图片,我收到错误:

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'

target 'Target' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

 # Pods for Target

  target 'TargetTests' do
    inherit! :search_paths
    pod 'Firebase', '>= 2.5.0'
    # Pods for testing
 end

end

有人知道是否有办法解决这个问题?

对于上下文:这是天赋纹理函数:

Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': Tainted canvases may not be loaded.

其中tagpro.renderer.getFlairTexture = function(e, t) { var n = PIXI.TextureCache[e]; if (!n) { var r = document.createElement("canvas"); r.width = 16, r.height = 16; var i = r.getContext("2d"); i.drawImage($('#flair').get(0), t.x * 16, t.y * 16, 16, 16, 0, 0, 16, 16), n = PIXI.Texture.fromCanvas(r), PIXI.TextureCache[e] = n } return n } 只是一个来自实际游戏网站(http://static.koalabeast.com/images/flair.png)的图片。

1 个答案:

答案 0 :(得分:1)

试一试:

var img = $('#flair').get(0);
img.crossOrigin = "Anonymous";
i.drawImage(img, t.x * 16, t.y * 16, 16, 16, 0, 0, 16, 16);