[SOLVED] Problem with FlxSprite

  • I attempted to add a sprite into my state:

    import flixel.FlxSprite;
    import flixel.FlxState;
    class PlayState extends FlxState
        override public function create():Void
            var spr:FlxSprite = new FlxSprite();
        override public function update(elapsed:Float):Void

    And this is my testSprite.png:(testSprite.png was created by mspaint and saved as a PNG.)

    But when I was running my project, I saw nothing on the screen. So I traced my spr.graphic:

    PlayState.hx:16: { assetsKey => assets/images/testSprite.png, width => 0, _useCount => 1, frameCollectionTypes => [], frameCollections => { root => { left => null, right => null, _height => 1, key => IMAGE, value => [(frames: [(name: null)] | type: IMAGE)] } }, unique => false, _imageFrame => (frames: [(name: null)] | type: IMAGE), _destroyOnNoUse => true, bitmap => { __handle => null, __transparent => true }, isDumped => false, key => assets/images/testSprite.png, height => 0, persist => false }

    width and height were unexpected 0 ! I tried to indicate width and height manually but no helps.

    So what's wrong?


    I try to add another one sprite in the same way, but it works.
    The another sprite(ship.png from ScaleMode Example):
    Now that this one could be added , then why my sprite not ?

    Another interesting phenomena

    Since testSprite.png was failed to add, other sprites could not name after it or it will not be able to be added in, either.
    For example

    testSprite.png fails and I renamed it as obsoleted.png.Then I rename the ship.png, which was successfully added previously, as testSprite.png and interestingly, the new testSprite.png could not be added in for now till it's renamed as other names but testSprite.png.

    Now I delete the current obsoleted.png and renamed testSprite.png(originally is ship.png) as obsoleted.png, and it fails again!

    Is that an issue?

  • Try to call super.create() at the beginning. I don't know, but i can imagin your state gets initialized in create().

  • @gamedevbynight Thanks though it doesn't work actually.

  • The problem is your PNG star image actually has a BMP file format. You should use drop-down menu in your paint app's save dialog to select the format, and not type the extension manually.

  • @starry-abyss Ah thanks, I remembered that I initially made a txt and manually changed its extension as png and then edited it with mspaint and saved again.Now I use "Save as..." to replace this sprite and it's solved!

    But as for the phenomena, is it an unexpected issue?

  • Extension is just a part of filename, the codec to use is specified by flags and signatures in the beginning of the file's contents. Windows and probably HaxeFlixel rely on extensions to distinguish between formats. IrfanView, on the other hand, will show a warning message if extension and format don't correspond each other.

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.