AxCache.texture accept bitmaps

Discuss suggestions to improve the Axel library.

AxCache.texture accept bitmaps

Postby Rhuno » Thu Sep 04, 2014 8:08 am

Not a big deal, but makes things just a little simpler if AxCache.texture can accept a regular bitmap. I added one more else if to the code as shown below:

Code: Select all
var rawBitmap:BitmapData;
if (resource is Class) {
    if (textures[resource] != null) {
        return textures[resource];
    rawBitmap = (new resource() as Bitmap).bitmapData;
} else if (resource is BitmapData) {
    rawBitmap = resource;
else if (resource is Bitmap) {
    // allow regular bitmaps to be sent in
    rawBitmap = (resource as Bitmap).bitmapData;
} else {
    throw new Error("Invalid resource:", resource);

This allows me to call .load on an AxSprite and send in a Bitmap object. I could have easily just called load and sent the bitmap's bitmapData, but I'd rather just do it once in the texture function and be done with it. Is there any particular reason to NOT do this? :)
Posts: 4
Joined: Mon Aug 06, 2012 5:35 pm

Re: AxCache.texture accept bitmaps

Postby Arkeus » Thu Sep 04, 2014 6:21 pm

I guess the biggest reason not to is the same for bitmapdata: It's not cached. If you're doing this for something like an enemy, each enemy will end up creating and uploading a separate texture, and texture swapping between draws, which is memory intensive and slow. You really only want to do this for things that you're only loading once, or that you definitely don't want cached. However, used with care, there's no reason not to.
User avatar
Site Admin
Posts: 363
Joined: Mon Mar 26, 2012 12:43 am

Return to Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest