Author Topic: working with images  (Read 1369 times)

pixelrevision

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
working with images
« 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.

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: working with images
« Reply #1 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?
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

pixelrevision

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: working with images
« Reply #2 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).

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: working with images
« Reply #3 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/
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

pixelrevision

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: working with images
« Reply #4 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"

Titch

  • Contributor
  • ****
  • Posts: 270
  • Karma: +0/-0
  • Thing with the guy in the place.
    • View Profile
Re: working with images
« Reply #5 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);
Free cake whippings every day at #flixel on irc.freenode.net.

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: working with images
« Reply #6 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.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

pixelrevision

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: working with images
« Reply #7 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