From 2747de79cbb4d2b4eecda02bf40dcc95db64a114 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sat, 28 Aug 2021 12:41:15 -0400 Subject: [PATCH] anim shit for stages --- source/BGSprite.hx | 49 ++++++++++++++++++++++++++++++++------------- source/PlayState.hx | 21 +++++++++++-------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/source/BGSprite.hx b/source/BGSprite.hx index 89bcb7f0c..45894efa6 100644 --- a/source/BGSprite.hx +++ b/source/BGSprite.hx @@ -9,32 +9,53 @@ class BGSprite extends FlxSprite */ public var idleAnim:String; - public function new(image:String, x:Float = 0, y:Float = 0, parX:Float = 1, parY:Float = 1, ?daAnimations:Array, ?loopingAnim:Bool = false) + /** + * NOTE: loadOldWay param is just for current backward compatibility! Will be moved later! + */ + public function new(image:String, x:Float = 0, y:Float = 0, parX:Float = 1, parY:Float = 1, ?daAnimations:Array, ?loopingAnim:Bool = false, + ?loadOldWay:Bool = true) { super(x, y); - if (daAnimations != null) + if (loadOldWay) { - frames = Paths.getSparrowAtlas(image); - for (anims in daAnimations) + if (daAnimations != null) { - animation.addByPrefix(anims, anims, 24, loopingAnim); - animation.play(anims); - - if (idleAnim == null) - idleAnim = anims; + setupSparrow(image, daAnimations, loopingAnim); + } + else + { + justLoadImage(image); } - } - else - { - loadGraphic(Paths.image(image)); - active = false; } scrollFactor.set(parX, parY); antialiasing = true; } + public function setupSparrow(image:String, daAnimations:Array, ?loopingAnim:Bool = false) + { + frames = Paths.getSparrowAtlas(image); + for (anims in daAnimations) + { + var daLoop:Bool = loopingAnim; + if (loopingAnim == null) + daLoop = false; + + animation.addByPrefix(anims, anims, 24, daLoop); + animation.play(anims); + + if (idleAnim == null) + idleAnim = anims; + } + } + + public function justLoadImage(image:String) + { + loadGraphic(Paths.image(image)); + active = false; + } + public function dance():Void { if (idleAnim != null) diff --git a/source/PlayState.hx b/source/PlayState.hx index d14d543eb..f6df6f2e7 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -526,13 +526,6 @@ class PlayState extends MusicBeatState tankSky.velocity.x = FlxG.random.float(5, 15); add(tankSky); - // need to implement animated effects, prob not too hard? - var smokeLeft:BGSprite = new BGSprite('smokeLeft', -200, -100, 0.4, 0.4, ['SmokeBlurLeft'], true); - add(smokeLeft); - - var smokeRight:BGSprite = new BGSprite('smokeRight', 1100, -100, 0.4, 0.4, ['SmokeRight'], true); - add(smokeRight); - // tankGround. tankWatchtower = new BGSprite('tankWatchtower', 100, 50, 0.5, 0.5, ['watchtower gradient color']); @@ -991,7 +984,12 @@ class PlayState extends MusicBeatState for (prop in parsed.propsBackground) { - var funnyProp:BGSprite = new BGSprite(prop.path, prop.x, prop.y, prop.scrollX, prop.scrollY); + var funnyProp:BGSprite = new BGSprite(prop.path, prop.x, prop.y, prop.scrollX, prop.scrollY, null, false, false); + + if (prop.animBullshit != null) + funnyProp.setupSparrow(prop.path, prop.animBullshit.anims, prop.animBullshit.isLooping); + else + funnyProp.justLoadImage(prop.path); funnyProp.setGraphicSize(Std.int(funnyProp.width * prop.scaleX), Std.int(funnyProp.height * prop.scaleY)); funnyProp.updateHitbox(); @@ -3203,4 +3201,11 @@ typedef Props = var path:String; var scaleX:Float; var scaleY:Float; + var ?animBullshit:PropAnimData; +} + +typedef PropAnimData = +{ + var isLooping:Bool; + var anims:Array; }