Skip to content

Commit

Permalink
FlxSprite: fix default graphic not showing on HTML5
Browse files Browse the repository at this point in the history
  • Loading branch information
Gama11 committed Sep 20, 2016
1 parent a2c8018 commit 2da3523
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 9 additions & 7 deletions flixel/FlxSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import flixel.util.FlxColor;
import flixel.util.FlxDestroyUtil;
using flixel.util.FlxColorTransformUtil;

@:keep @:bitmap("assets/images/logo/default.png")
private class GraphicDefault extends BitmapData {}

// TODO: add updateSizeFromFrame bool which will tell sprite whether to update it's size to frame's size (when frame setter is called) or not (useful for sprites with adjusted hitbox)
// And don't forget about sprites with clipped frames: what i should do with their size in this case?

Expand Down Expand Up @@ -621,13 +618,19 @@ class FlxSprite extends FlxObject
animation.update(elapsed);
}

@:noCompletion
private function checkEmptyFrame()
{
if (_frame == null)
loadGraphic("flixel/images/logo/default.png");
}

/**
* Called by game loop, updates then blits or renders current frame of animation to the screen
*/
override public function draw():Void
{
if (_frame == null)
loadGraphic(FlxGraphic.fromClass(GraphicDefault));
checkEmptyFrame();

if (alpha == 0 || _frame.type == FlxFrameType.EMPTY)
return;
Expand Down Expand Up @@ -891,8 +894,7 @@ class FlxSprite extends FlxObject
@:noCompletion
private function calcFrame(RunOnCpp:Bool = false):Void
{
if (frame == null)
loadGraphic(FlxGraphic.fromClass(GraphicDefault));
checkEmptyFrame();

if (FlxG.renderTile && !RunOnCpp)
return;
Expand Down
5 changes: 4 additions & 1 deletion include.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

<assets path="assets/fonts/nokiafc22.ttf" rename="flixel/fonts/nokiafc22.ttf" embed="true" />
<assets path="assets/fonts/monsterrat.ttf" rename="flixel/fonts/monsterrat.ttf" embed="true" />
<assets path="assets/images/ui/button.png" rename="flixel/images/ui/button.png" embed="true" unless="unit-test html5" />
<section unless="unit-test html5">
<assets path="assets/images/ui/button.png" rename="flixel/images/ui/button.png" embed="true" />
<assets path="assets/images/logo/default.png" rename="flixel/images/logo/default.png" embed="true" />
</section>

<set name="legacy" unless="next" />

Expand Down

0 comments on commit 2da3523

Please sign in to comment.