Skip to content

Commit 2f00e84

Browse files
fix: Flappybalt: bounce panels resetting thier sprites to default on clearSave (#372)
1 parent e3d1a11 commit 2f00e84

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

Arcade/Flappybalt/source/PlayState.hx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,20 @@ class PlayState extends FlxState
6969
if (Reg.highScore > 0)
7070
_highScore.text = Std.string(Reg.highScore);
7171

72-
// The left bounce panel. Drawn via code in Reg to fit screen height.
72+
// The bounce panel. Drawn via code in Reg to fit screen height.
73+
final bounceImage = Reg.createBounceImage(FlxG.height - 34);
7374

75+
// The left bounce panel.
76+
7477
_bounceLeft = new FlxSprite(1, 17);
75-
_bounceLeft.loadGraphic(Reg.getBounceImage(FlxG.height - 34), true, 4, FlxG.height - 34);
78+
_bounceLeft.loadGraphic(bounceImage, true, 4, FlxG.height - 34);
7679
_bounceLeft.animation.add("flash", [1, 0], 8, false);
7780
add(_bounceLeft);
7881

7982
// The right bounce panel.
8083

8184
_bounceRight = new FlxSprite(FlxG.width - 5, 17);
82-
_bounceRight.loadGraphic(Reg.getBounceImage(FlxG.height - 34), true, 4, FlxG.height - 34);
85+
_bounceRight.loadGraphic(bounceImage, true, 4, FlxG.height - 34);
8386
_bounceRight.animation.add("flash", [1, 0], 8, false);
8487
add(_bounceRight);
8588

Arcade/Flappybalt/source/Reg.hx

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,36 @@ class Reg
3737
* Draws the bounce panels. Useful for mobile devices with weird resolutions.
3838
*
3939
* @param Height The height of the panel to draw.
40-
* @return A BitmapData object representing the paddle. Cached for the second paddle to save time.
40+
* @return A BitmapData object representing the paddle.
4141
*/
42-
static public function getBounceImage(Height:Int):BitmapData
42+
static public function createBounceImage(Height:Int):BitmapData
4343
{
44-
if (_bitmapData != null)
45-
return _bitmapData;
44+
var bitmapData:BitmapData = new BitmapData(8, Height, false, GREY_MED);
45+
var rect:Rectangle;
4646

47-
_bitmapData = new BitmapData(8, Height, false, GREY_MED);
47+
rect = new Rectangle(4, 0, 4, Height);
48+
bitmapData.fillRect(rect, GREY_LIGHT);
49+
rect = new Rectangle(0, 1, 1, Height - 2);
50+
bitmapData.fillRect(rect, GREY_DARK);
51+
rect.x = 3;
52+
bitmapData.fillRect(rect, GREY_DARK);
53+
rect = new Rectangle(1, 0, 2, 1);
54+
bitmapData.fillRect(rect, GREY_DARK);
55+
rect.y = Height - 1;
56+
bitmapData.fillRect(rect, GREY_DARK);
57+
rect = new Rectangle(4, 1, 1, Height - 2);
58+
bitmapData.fillRect(rect, WHITE);
59+
rect.x = 7;
60+
bitmapData.fillRect(rect, WHITE);
61+
rect = new Rectangle(5, 0, 2, 1);
62+
bitmapData.fillRect(rect, WHITE);
63+
rect.y = Height - 1;
64+
bitmapData.fillRect(rect, WHITE);
4865

49-
_rect = new Rectangle(4, 0, 4, Height);
50-
_bitmapData.fillRect(_rect, GREY_LIGHT);
51-
_rect = new Rectangle(0, 1, 1, Height - 2);
52-
_bitmapData.fillRect(_rect, GREY_DARK);
53-
_rect.x = 3;
54-
_bitmapData.fillRect(_rect, GREY_DARK);
55-
_rect = new Rectangle(1, 0, 2, 1);
56-
_bitmapData.fillRect(_rect, GREY_DARK);
57-
_rect.y = Height - 1;
58-
_bitmapData.fillRect(_rect, GREY_DARK);
59-
_rect = new Rectangle(4, 1, 1, Height - 2);
60-
_bitmapData.fillRect(_rect, WHITE);
61-
_rect.x = 7;
62-
_bitmapData.fillRect(_rect, WHITE);
63-
_rect = new Rectangle(5, 0, 2, 1);
64-
_bitmapData.fillRect(_rect, WHITE);
65-
_rect.y = Height - 1;
66-
_bitmapData.fillRect(_rect, WHITE);
67-
68-
return _bitmapData;
66+
return bitmapData;
6967
}
7068

7169
// This is all stuff used for drawing the paddles.
72-
static var _bitmapData:BitmapData;
73-
static var _rect:Rectangle;
7470

7571
inline static var WHITE:Int = 0xffFFFFFF;
7672
inline static var GREY_LIGHT:Int = 0xffB0B0BF;

0 commit comments

Comments
 (0)