2014-09-28 23 views
0

在我的遊戲中,我試圖在一個圖像文件中將我的所有GUI紋理使用精靈表。但我不知道如何使用由矩形定義的圖像資源的一部分來創建精靈。我不想使用紋理打包器,我有一個替代的更簡單的免費紋理打包程序,它將圖像文件中的紋理捆綁在一起,併爲我提供了json文件中的映射。我可以解析json,但是一旦我得到了定義單個紋理和表單圖像的矩形,我不知道如何處理它們。在一個圖像文件中使用多個紋理

回答

1

根據Beeblerox

在flixel當前版本

你能做到這樣:

var cached:CachedGraphics = FlxG.bitmap.add(Graphic); // where Graphic is the path to image in assets 
var textureRegion:TextureRegion = new TextureRegion(cached, rect.x, rect,y, rect.width, rect.height, 0, 0, rect.width, rect.height); // where rect is the rectangular area you want to load into sprite 
sprite.loadGraphic(textureRegion); 

在未來的版本,這是在作品將被更改爲:

var imageFrame:ImageFrame = ImageFrame.fromRectangle("path/to/image", rect); 
sprite.frames = imageFrame; 
0

基本上你需要:

  • 創建一個新的BitmapData對象。
  • 在此對象上調用copyPixels(sourceBitmapData:BitmapData,sourceRect:Rectangle,destPoint:Point),其中sourceBitmapData是加載的spritesheet BitmapData。
  • 從此BitmapData中構建一個新的display.flash.Bitmap對象。
  • call addChild(bm)其中bm是您剛創建的位圖,以將其顯示在您想要的容器中。

在這裏看到:

相關問題