Flixel Forums

development => help => Topic started by: pixelrevision on Wed, Mar 2, 2011

Title: working with images
Post by: pixelrevision on Wed, Mar 2, 2011
I am noticing most of the image assets in flixel seem to require a Class.  I would like to ba able to load up my image assets externally, does anyone know how to convert loaded bitmap data into something that can be processed?

example of what I would like to do:
var mapBmd:BitmapData = assetManager.getBitmapDataByName("someBitmapName");
map.loadMap(mapString, mapBmd, 16, 16);

In this example it fails because mapBmd is a instance not a class.
Title: Re: working with images
Post by: photonstorm on Wed, Mar 2, 2011
Do you want to literally load them externally, like have every single PNG as a separate file that the SWF loads in? (in which case I'd ask why? it will make your game un-distributable)

Or do you just want to be able to package the assets up in something else, say the Flash IDE, and use them with Flixel?
Title: Re: working with images
Post by: pixelrevision on Wed, Mar 2, 2011
I am looking to do is use the images in conjunction with json on a level by level basis.  I am building for the web, not standalone distribution.  There wouldn't me many images associated with each level, (3-5 maybe).
Title: Re: working with images
Post by: photonstorm on Wed, Mar 2, 2011
Ok cool, then I would strongly recommend using LoaderMax: https://www.greensock.com/loadermax/

Or if for some reason you feel a burning need to roll your own then I'd recommend reading this: http://chargedweb.com/labs/2010/03/12/flex-cursormanager-vs-jloa/
Title: Re: working with images
Post by: pixelrevision on Wed, Mar 2, 2011
Oh sorry, let me rephrase my question.  I'm not having issues loading the images.  I am having problems getting them into flixel.
The issue is that most of the flixel creation methods only accept "Class" as the parameter type.  I am trying to figure out if when using a map or sprite how to actually pass the bitmap data in or convert my bitmap data to something that will be accepted.

So for instance in the load map function:
public function loadMap(MapData:String, TileGraphic:Class, TileWidth:uint = 0, TileHeight:uint = 0)
I need to figure out how to pass a valid bitmapdata to "TileGraphic"
Title: Re: working with images
Post by: Titch on Wed, Mar 2, 2011
Code: [Select]
public function loadGraphic(Graphic:Class,Animated:Boolean=false,Reverse:Boolean=false,Width:uint=0,Height:uint=0,Unique:Boolean=false):FlxSprite
{
_bakedRotation = 0;
_pixels = FlxG.addBitmap(Graphic,Reverse,Unique);

This would probably be a good place to start. Extend FlxSprite and add a new function that works like this one but uses this:

Code: [Select]
loadExternalGraphic(Graphic:Bitmap,Animated:Boolean=false,Reverse:Boolean=false,Width:uint=0,Height:uint=0,Unique:Boolean=false):FlxSprite
{
_bakedRotation = 0;
_pixels = FlxG.addBitmap(Graphic.bitmapData,Reverse,Unique);
Title: Re: working with images
Post by: photonstorm on Thu, Mar 3, 2011
You should check out the links I posted. They solve your problem (I understood what you needed :) )

LoaderMax solves it because the loaded objects can be got at as classes. The blog entry posted does a similar thing. Check them out.
Title: Re: working with images
Post by: pixelrevision on Thu, Mar 3, 2011
In case anyone else comes here and is doing a search for this I did find this tutorial.
http://www.iokat.com/posts/3/loading-external-images-for-use-with-flixel-sprites