除了openfl.Assets
,OpenFL支持@:bitmap
,@:sound
,@:font
和@:file
嵌入標籤。
前者需要<assets path="to/assets" />
在您的項目XML文件中,並在Windows上將文件複製到您的可執行文件旁邊。
嵌入標籤要求您的資產文件基於其嵌入方式位於源路徑中,因此在項目文件中使用<source path="to/assets" />
。
下面是一個使用@:bitmap
標籤的例子:
package;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
@:bitmap("nme.png") class Image extends BitmapData {}
class Main extends Sprite {
public function new() {
super();
var bitmap = new Bitmap (new Image (0, 0));
addChild (bitmap);
bitmap.x = (stage.stageWidth - bitmap.width)/2;
bitmap.y = (stage.stageHeight - bitmap.height)/2;
}
}
使用嵌入標籤,該資產將是您的可執行文件中。
謝謝!我從NME遷移到OpenFL來做到這一點,我不能對結果感到滿意。另一個快速提示:我怎樣才能禁用Alt + Enter功能? –
我將如何使用@:file來嵌入swf庫?你能否在上面的答案中添加一個例子?謝謝 – simo