簡體   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