[SOLVED] Problem with FlxSprite
-
I attempted to add a sprite into my state:
package; import flixel.FlxSprite; import flixel.FlxState; class PlayState extends FlxState { override public function create():Void { var spr:FlxSprite = new FlxSprite(); spr.loadGraphic(AssetPaths.testSprite__png); add(spr); super.create(); } override public function update(elapsed:Float):Void { super.update(elapsed); } }
And this is my
testSprite.png
:(testSprite.png
was created bymspaint
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
andheight
were unexpected 0 ! I tried to indicatewidth
andheight
manually but no helps.So what's wrong?
Addition
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 exampletestSprite.png
fails and I renamed it asobsoleted.png
.Then I rename theship.png
, which was successfully added previously, astestSprite.png
and interestingly, the newtestSprite.png
could not be added in for now till it's renamed as other names buttestSprite.png
.Now I delete the current
obsoleted.png
and renamedtestSprite.png
(originally isship.png
) asobsoleted.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.