I want to show image with alpha channel over preloader's background for flash target with haxe nme. This need seems to be common when it comes to a preloader.
I find several possible way to do that, but with out luck on any of them. Since I make a custom Preloader class which inherits default NMEPreloader, all my trails&errors are in this class.
Method #1 - nme.Assets approach - Runtime Error
I tried call Assets.loadBitmapData("assets/img/miniMoon.png")
in Preloader's constructer. Error occur at run time:
[Fault] exception, information=ArgumentError: Error #2015: Invalid BitmapData.
with call stack:
flash.display::BitmapData/ctor
flash.display::BitmapData
NME_assets_img_minimoon_png1 at H:\MWHx\export\flash\haxe\ApplicationMain.hx:2053
Type$/createInstance at C:\Motion-Tween\haxe\std\flash\_std\Type.hx:136
nme.installer::Assets$/getBitmapData at H:\MWHx\export\flash\haxe\nme\installer\Assets.hx:721
Preloader at H:\MWHx\source\Preloader.hx:55
...
I wonder whether nme.Assets class is ready to use during preloading.
Method #2 Embed in Flash Way - Rendered without transparency
Throuth it's not NME's favor to use embed, I have tried this:
@:bitmap("assets/img/miniMoon.png") class BDmoon extends BitmapData {}
...
var moon:Bitmap;
...
moon = new Bitmap(new BDmoon(32,32,true,0x00000000));
It just runs and but the image shown with out transparency, all pixels with alpha 0 is rendered white against background.
As a further test, I use moon.alpha = 0.5;
then I can see through the image. So maybe this is a problem of losing alpha channel values during embedding in nme.
A preloader with small animation or a tiny game can be fun. I hope there is a solution for this. Thanks!
references: NME forum topic : Embed Transparent Png Image
Sorry for this, but it's a problem of my OWN IMAGE FILE !
Since I don't know how to close the silly question to new answers. I put up a clean solution here.
If you want to use image in preloader, here is my code. Tested under NME 3.5.5.
@:bitmap("assets/img/miniMoon.png") class BDmoon extends nme.display.BitmapData{}
class MyPreloader extends NMEPreloader
{
public var embedBmp:nme.display.Bitmap;
public var bmpFromAssets:nme.display.Bitmap;
public function new(){
super();
embedBmp = new nme.display.Bitmap(new BDmoon(64, 64, true));
addChild(embedBmp);
// Line below cause problem, nme.Assets not ready in preloader
bmpFromAssets = new nme.display.Bitmap(Assets.getBitmapData("assets/img/miniMoon.png"));
addChild(bmpFromAssets);
}
public override function onLoaded()
{
// dispatchEvent (new Event (Event.COMPLETE));
}
}
Refer: http://haxeflixel.com/forum/help/nme-355-preloader-flash-error