Code Monkey home page Code Monkey logo

Comments (10)

FlixelCommunityBot avatar FlixelCommunityBot commented on September 22, 2024

Comment by: IQAndreas

The "Graphic" you pass in should be a Class that extends Bitmap (NOT ByteArray or BitmapData).

What does your code look like?

from flixel.

moly avatar moly commented on September 22, 2024

There should be a more descriptive error message if the user passes in an invalid class. It might also be better to have the function return the default graphic rather than throwing an exception. I'm thinking something like:

if(!checkBitmapCache(Key))
{
    var bitmap:Bitmap = new Graphic() as Bitmap;
    if(bitmap == null)
    {
        FlxG.log("Error: " + Graphic + " must extend flash.display.Bitmap.");
        return FlxG.addBitmap(FlxSprite.ImgDefault);
    }
    _cache[key] = bitmap.bitmapData;
}

from flixel.

IQAndreas avatar IQAndreas commented on September 22, 2024

There should be a more descriptive error message if the user passes in an invalid class.

Good idea!

"Error: " + Graphic + " must extend flash.display.Bitmap."

Of course, with the old code, you could pass in any class as long as it has a bitmapData property. It didn't have to be a Bitmap. There could be cases where this could come in handy, such as if the BitmapData is generated rather than loaded through a Loader.

Though, in such a case, it may be better adding another method named addBitmapData where you can explicitly pass in the BitmapData instance rather than a class.

from flixel.

Dovyski avatar Dovyski commented on September 22, 2024

I liked the warning message @moly suggested. About the the bitmapData property @IQAndreas said, I agree it might be better idea to create a method named addBitmapData() to explicity pass in the BitmapData rather than a class.

from flixel.

IQAndreas avatar IQAndreas commented on September 22, 2024

@Dovyski I noticed you were assigned to this issue. Do you already have the code ready for this fix, or shall I write some up and add the pull request?

I think we should separate off adding the error message in this release, and adding the addBitmapData() function to the next release.

from flixel.

Dovyski avatar Dovyski commented on September 22, 2024

I am sorry, I assigned this issue to me but stopped working when I noticed there would be some conflicts during the merge. I did nothing so far, @IQAndreas , so feel free to implement what was discussed. Bare in mind there are some pending pull requests that affect that very area of the code.

I agree with you about the error message and the new method. Leave addBitmapData() for the next release.

from flixel.

IQAndreas avatar IQAndreas commented on September 22, 2024

I assigned this issue to me but stopped working when I noticed there would be some conflicts during the merge.

It seems that all pull requests that modify FlxG have been merged by now, so I'll go ahead and add a pull request for this one.

from flixel.

IQAndreas avatar IQAndreas commented on September 22, 2024

I made two additional tweaks in the pull requst:

  • Added getClassName to make the log ouput clearer
  • Passed along the "reverse" parameter to the "default image" sprite. I think it might make a difference?

from flixel.

Dovyski avatar Dovyski commented on September 22, 2024

The getClassName() will be really useful.

About the "reverse", I can't tell if that makes any difference. In the context of the fix, the default image is just a "placeholder", so it's not that important to reverse it or not.

from flixel.

IQAndreas avatar IQAndreas commented on September 22, 2024

Resolved by 58f1e1f

from flixel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.