繁体   English   中英

Animate库的StageGL跨域错误

[英]StageGL cross-domain error with Animate library

我正在使用Animate作为资产生成器并使用StageGL处理对象来构建游戏。 我所有的对象都是存储在Animate生成的主Spritesheet中的SPOT位图纹理。

如果我尝试创建一个新的位图以手动编码其中一个精灵的效果(我想使用sourceRect将位图拆分为片段,然后“溶解”),则会收到跨域错误-尽管我正在运行通过Webpack开发服务器(即localhost:3000)将该站点加载,并且精灵可以在其他位置正常加载(例如,如果我只是在舞台上添加已经包含位图的MovieClip)。

var srcImg = new lib.MySourceImage(); //This is the Sprite in the Animate library
var bmp = new createjs.Bitmap(srcImg);
stage.addChild(bmp);

该位图可以很好地作为其父库MovieClip的一部分,但是我需要该位图才能执行sourceRect切片...有什么想法吗?

我已经找到了解决方案,尽管我仍然不完全了解跨域限制。

    var img = new Image();
    img.crossOrigin = "Anonymous";
    img.src = loader.getItem("mySpriteSheet").src; // Get the spritesheet source image again
    var frame = new lib.MySourceImage().currentFrame; // In case the sprite moves around in later versions of the spritesheet, get the current position from the library
    var thisFrameData = ss["mySpriteSheet"].getFrame(frame);

我看不到为什么我需要再次标记图像的crossOrigin属性,因为我认为必须在Animate lib首次加载图像时按原样加载图像(虽然我看不到任何专门定义该图像的地方) )。

一旦获得了框架的源数据(基本上是一个矩形),就可以按照Lanny的建议 ,使用x,y,width,height从该图像定义新的精灵。 这恰好满足了我的需要,并且看起来足够高效。

这确实使我感到效率低下/不必要,不必再次“加载”图像,但是我看不到明显的替代方法。 任何建议欢迎!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM