简体   繁体   English

Animate库的StageGL跨域错误

[英]StageGL cross-domain error with Animate library

I'm building a game using Animate as an asset builder, using StageGL to handle the objects. 我正在使用Animate作为资产生成器并使用StageGL处理对象来构建游戏。 All of my objects are SPOT bitmap textures stored in the main spritesheet that Animate generates. 我所有的对象都是存储在Animate生成的主Spritesheet中的SPOT位图纹理。

If I try to create a new Bitmap to manually code an effect on one of the sprites (I want to split the bitmap into fragments using sourceRect and then 'dissolve'), I get a cross-origin error - despite the fact I am running the site through a Webpack dev server (ie, localhost:3000) and the sprites load fine elsewhere (say, if I just add a MovieClip already containing a bitmap to the stage). 如果我尝试创建一个新的位图以手动编码其中一个精灵的效果(我想使用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);

The bitmap will add fine as part of its parent library MovieClip, but I need the bitmap to be able to perform the sourceRect slicing... Any ideas? 该位图可以很好地作为其父库MovieClip的一部分,但是我需要该位图才能执行sourceRect切片...有什么想法吗?

I have found a solution, altho I still don't fully understand the cross-origin restriction. 我已经找到了解决方案,尽管我仍然不完全了解跨域限制。

    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);

I don't see why I should need to mark the crossOrigin property of the image again, as I presume it must be loaded as such when the Animate lib loads it for the first time (altho I can't see anywhere that specifically defines that). 我看不到为什么我需要再次标记图像的crossOrigin属性,因为我认为必须在Animate lib首次加载图像时按原样加载图像(虽然我看不到任何专门定义该图像的地方) )。

Once I've got the frame's source data (basically a rectangle), I can use the x,y,width,height to define the new sprites from this image, along the lines of this suggestion from Lanny. 一旦获得了框架的源数据(基本上是一个矩形),就可以按照Lanny的建议 ,使用x,y,width,height从该图像定义新的精灵。 This does exactly what I need to do, and seems performant enough. 这恰好满足了我的需要,并且看起来足够高效。

It does strike me as inefficient/unnecessary to have to 'load' the image again, but I can't see an obvious alternative. 这确实使我感到效率低下/不必要,不必再次“加载”图像,但是我看不到明显的替代方法。 Any suggestions welcome! 任何建议欢迎!

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

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