In other platforms i could just use something like [Embed(source="logo.gif")] or @:bitmap, but it seems there is no option for that for Windows/Other Cpp platforms.
I tried to use the EmbedAssets lib but it's outdated.
I also tried using the nmml file resource tag. With this i could get the image as haxe.sys.io.Bytes, but to use i need to convert haxe.sys.io.Bytes to nme.utils.ByteArray. I have not found a way to do this.
So, what can i do to embed images on a haxe/nme project when deploying to Windows?
In addition to openfl.Assets
, OpenFL supports @:bitmap
, @:sound
, @:font
and @:file
embed tags.
The former requires <assets path="to/assets" />
in your project XML file, and on Windows, will copy the files alongside your executable.
The embed tags require that your asset files are in your source path based on the way they are embedded, so use <source path="to/assets" />
in the project file.
Here is an example that uses the @:bitmap
tag:
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;
}
}
Using embed tags, the asset will be inside your executable.