From c61529d40f8bb92e10daba29a55e7ecd1c7bf439 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sun, 11 Apr 2021 19:08:36 -0400 Subject: [PATCH] sprite animation shit idk lol who cares loL! --- Project.xml | 6 ++ source/CoolUtil.hx | 59 ------------- source/CutsceneAnimTestState.hx | 70 ++++++++-------- source/PlayState.hx | 38 +++++++-- source/TitleState.hx | 5 ++ source/animate/FlxAnimate.hx | 144 ++++++++++++++++++++++++++++++++ 6 files changed, 217 insertions(+), 105 deletions(-) create mode 100644 source/animate/FlxAnimate.hx diff --git a/Project.xml b/Project.xml index 9e90b237e..3b66a7189 100644 --- a/Project.xml +++ b/Project.xml @@ -126,6 +126,12 @@ + + + + + + diff --git a/source/CoolUtil.hx b/source/CoolUtil.hx index 2e93961c1..3ec3cf1e1 100644 --- a/source/CoolUtil.hx +++ b/source/CoolUtil.hx @@ -54,63 +54,4 @@ class CoolUtil { return lerp * (FlxG.elapsed / (1 / 60)); } - - public static function fromAnimate(Source:FlxGraphicAsset, Description:String):FlxAtlasFrames - { - var graphic:FlxGraphic = FlxG.bitmap.add(Source); - if (graphic == null) - return null; - - var frames:FlxAtlasFrames = FlxAtlasFrames.findFrame(graphic); - if (frames != null) - return frames; - - if (graphic == null || Description == null) - return null; - - frames = new FlxAtlasFrames(graphic); - - var data:AnimateObject; - - var json:String = Description; - - trace(json); - - if (Assets.exists(json)) - json = Assets.getText(json); - - data = cast Json.parse(json).ATLAS; - - for (sprite in data.SPRITES) - { - // probably nicer way to do this? Oh well - var swagSprite:AnimateSprite = sprite.SPRITE; - - var rect = FlxRect.get(swagSprite.x, swagSprite.y, swagSprite.w, swagSprite.h); - - var size = new Rectangle(0, 0, rect.width, rect.height); - - var offset = FlxPoint.get(-size.left, -size.top); - var sourceSize = FlxPoint.get(size.width, size.height); - - frames.addAtlasFrame(rect, sourceSize, offset, swagSprite.name); - } - - return frames; - } -} - -typedef AnimateObject = -{ - SPRITES:Array -} - -typedef AnimateSprite = -{ - var name:String; - var x:Int; - var y:Int; - var w:Int; - var h:Int; - var rotated:Bool; } diff --git a/source/CutsceneAnimTestState.hx b/source/CutsceneAnimTestState.hx index 5c7511e95..32d9cd3eb 100644 --- a/source/CutsceneAnimTestState.hx +++ b/source/CutsceneAnimTestState.hx @@ -1,5 +1,8 @@ package; +import animate.FlxAnimate; +import animateAtlasPlayer.assets.AssetManager; +import animateAtlasPlayer.core.Animation; import flixel.FlxG; import flixel.FlxSprite; import flixel.FlxState; @@ -8,6 +11,7 @@ import flixel.group.FlxGroup.FlxTypedGroup; import flixel.math.FlxPoint; import flixel.text.FlxText; import flixel.util.FlxColor; +import openfl.display.BitmapData; class CutsceneAnimTestState extends FlxState { @@ -38,17 +42,8 @@ class CutsceneAnimTestState extends FlxState debugTxt.color = FlxColor.BLUE; add(debugTxt); - for (i in 0...animShit.length) - { - var dummyLoader:FlxSprite = new FlxSprite(); - dummyLoader.loadGraphic(Paths.image('cutsceneStuff/gfHoldup-' + i)); - add(dummyLoader); - dummyLoader.alpha = 0.01; - dummyLoader.y = FlxG.height - 20; - } - - cutsceneGroup = new CutsceneCharacter(0, 0, 'gfHoldup'); - add(cutsceneGroup); + var animated:FlxAnimate = new FlxAnimate(10, 10); + add(animated); // createCutscene(0); // createCutscene(1); @@ -59,36 +54,37 @@ class CutsceneAnimTestState extends FlxState override function update(elapsed:Float) { - if (FlxG.keys.pressed.SHIFT) - { - if (FlxG.keys.justPressed.UP) - curSelected -= 1; - if (FlxG.keys.justPressed.DOWN) - curSelected += 1; + /* if (FlxG.keys.pressed.SHIFT) + { + if (FlxG.keys.justPressed.UP) + curSelected -= 1; + if (FlxG.keys.justPressed.DOWN) + curSelected += 1; - if (curSelected < 0) - curSelected = cutsceneGroup.members.length - 1; - if (curSelected >= cutsceneGroup.members.length) - curSelected = 0; - } - else - { - var valueMulti:Float = 1; + if (curSelected < 0) + curSelected = cutsceneGroup.members.length - 1; + if (curSelected >= cutsceneGroup.members.length) + curSelected = 0; + } + else + { + var valueMulti:Float = 1; - if (FlxG.keys.pressed.SPACE) - valueMulti = 10; + if (FlxG.keys.pressed.SPACE) + valueMulti = 10; - if (FlxG.keys.justPressed.UP) - cutsceneGroup.members[curSelected].y -= valueMulti; - if (FlxG.keys.justPressed.DOWN) - cutsceneGroup.members[curSelected].y += valueMulti; - if (FlxG.keys.justPressed.LEFT) - cutsceneGroup.members[curSelected].x -= valueMulti; - if (FlxG.keys.justPressed.RIGHT) - cutsceneGroup.members[curSelected].x += valueMulti; - } + if (FlxG.keys.justPressed.UP) + cutsceneGroup.members[curSelected].y -= valueMulti; + if (FlxG.keys.justPressed.DOWN) + cutsceneGroup.members[curSelected].y += valueMulti; + if (FlxG.keys.justPressed.LEFT) + cutsceneGroup.members[curSelected].x -= valueMulti; + if (FlxG.keys.justPressed.RIGHT) + cutsceneGroup.members[curSelected].x += valueMulti; + } - debugTxt.text = curSelected + " : " + cutsceneGroup.members[curSelected].getPosition(); + debugTxt.text = curSelected + " : " + cutsceneGroup.members[curSelected].getPosition(); + */ super.update(elapsed); } diff --git a/source/PlayState.hx b/source/PlayState.hx index 25a4ffcae..ea6243cfe 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -3,6 +3,8 @@ package; import Section.SwagSection; import Song.SwagSong; import WiggleEffect.WiggleEffectType; +import animateAtlasPlayer.assets.AssetManager; +import animateAtlasPlayer.core.Animation; import flixel.FlxBasic; import flixel.FlxCamera; import flixel.FlxG; @@ -37,6 +39,7 @@ import flixel.util.FlxTimer; import haxe.Json; import lime.utils.Assets; import openfl.Lib; +import openfl.display.BitmapData; import openfl.display.BlendMode; import openfl.display.StageQuality; import openfl.filters.ShaderFilter; @@ -1054,16 +1057,18 @@ class PlayState extends MusicBeatState var dummyLoaderShit:FlxGroup = new FlxGroup(); add(dummyLoaderShit); + /* + for (i in 0...7) + { + var dummyLoader:FlxSprite = new FlxSprite(); + dummyLoader.loadGraphic(Paths.image('cutsceneStuff/gfHoldup-' + i)); + dummyLoaderShit.add(dummyLoader); + dummyLoader.alpha = 0.01; + dummyLoader.y = FlxG.height - 20; + // dummyLoader.drawFrame(true); + } - for (i in 0...7) - { - var dummyLoader:FlxSprite = new FlxSprite(); - dummyLoader.loadGraphic(Paths.image('cutsceneStuff/gfHoldup-' + i)); - dummyLoaderShit.add(dummyLoader); - dummyLoader.alpha = 0.01; - dummyLoader.y = FlxG.height - 20; - // dummyLoader.drawFrame(true); - } + */ dad.visible = false; @@ -1103,6 +1108,21 @@ class PlayState extends MusicBeatState var fakeBF:Character = new Character(boyfriend.x, boyfriend.y, 'bf', true); bfTankCutsceneLayer.add(fakeBF); + // var atlasCutscene:Animation + // var animAssets:AssetManager = new AssetManager(); + + // var url = 'images/gfDemon'; + + // // animAssets.enqueueSingle(Paths.file(url + "/spritemap1.png")); + // // animAssets.enqueueSingle(Paths.file(url + "/spritemap1.json")); + // // animAssets.enqueueSingle(Paths.file(url + "/Animation.json")); + + // animAssets.loadQueue(function(asssss:AssetManager) + // { + // var daAnim:Animation = asssss.createAnimation('GF Turnin Demon W Effect'); + // FlxG.addChildBelowMouse(daAnim); + // }); + var bfCatchGf:FlxSprite = new FlxSprite(boyfriend.x - 10, boyfriend.y - 90); bfCatchGf.frames = Paths.getSparrowAtlas('cutsceneStuff/bfCatchesGF'); bfCatchGf.animation.addByPrefix('catch', 'BF catches GF', 24, false); diff --git a/source/TitleState.hx b/source/TitleState.hx index 5ec71ff27..8f052a791 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -376,6 +376,11 @@ class TitleState extends MusicBeatState } #end + if (FlxG.keys.justPressed.FIVE) + { + FlxG.switchState(new CutsceneAnimTestState()); + } + var gamepad:FlxGamepad = FlxG.gamepads.lastActive; if (gamepad != null) diff --git a/source/animate/FlxAnimate.hx b/source/animate/FlxAnimate.hx new file mode 100644 index 000000000..bdcb95730 --- /dev/null +++ b/source/animate/FlxAnimate.hx @@ -0,0 +1,144 @@ +package animate; + +import animateAtlasPlayer.assets.AssetManager; +import animateAtlasPlayer.core.Animation; +import flixel.FlxG; +import flixel.FlxSprite; +import flixel.graphics.FlxGraphic; +import flixel.graphics.frames.FlxAtlasFrames; +import flixel.math.FlxPoint; +import flixel.math.FlxRect; +import flixel.system.FlxAssets.FlxGraphicAsset; +import haxe.Json; +import openfl.Assets; +import openfl.display.Bitmap; +import openfl.display.BitmapData; +import openfl.geom.Point; +import openfl.geom.Rectangle; + +class FlxAnimate extends FlxSprite +{ + var myAnim:Animation; + var animBitmap:BitmapData; + + var loadedQueue:Bool = false; + + var swagFrames:Array = []; + + public function new(x:Float, y:Float) + { + super(x, y); + + // get fromAnimate() + // get every symbol / piece needed + // animate them? + + var swagAssets:AssetManager = new AssetManager(); + swagAssets.enqueueSingle(Paths.file('images/picoShoot/spritemap1.png')); + swagAssets.enqueueSingle(Paths.file('images/picoShoot/spritemap1.json')); + swagAssets.enqueueSingle(Paths.file('images/picoShoot/Animation.json')); + + swagAssets.loadQueue(function(assetMgr:AssetManager) + { + myAnim = assetMgr.createAnimation("Pico Saves them sequence"); + myAnim.cacheAsBitmap = true; + myAnim.opaqueBackground = null; + // myAnim.root.x += 200; + // myAnim.root.y += 200; + // myAnim.x += 200; + // myAnim.y += 200; + + var daAnim:BitmapData = new BitmapData(200, 200, true, 0x00000000); + daAnim.draw(myAnim); + animBitmap = new BitmapData(200, 200, true, 0x00000000); + animBitmap.draw(myAnim); + + loadGraphic(animBitmap); + // framePixels = animBitmap; + + loadedQueue = true; + }); + } + + var pointZero:Point = new Point(); + + private var lastFrame:Int = 0; + + override function draw() + { + super.draw(); + + if (loadedQueue) + { + if (lastFrame != myAnim.currentFrame) + { + lastFrame = myAnim.currentFrame; + // loadGraphic(animBitmap); + + animBitmap.draw(myAnim); + } + + // animBitmap.draw(myAnim); + } + } + + // This stuff is u + public static function fromAnimate(Source:FlxGraphicAsset, Description:String):FlxAtlasFrames + { + var graphic:FlxGraphic = FlxG.bitmap.add(Source); + if (graphic == null) + return null; + + var frames:FlxAtlasFrames = FlxAtlasFrames.findFrame(graphic); + if (frames != null) + return frames; + + if (graphic == null || Description == null) + return null; + + frames = new FlxAtlasFrames(graphic); + + var data:AnimateObject; + + var json:String = Description; + + trace(json); + + if (Assets.exists(json)) + json = Assets.getText(json); + + data = cast Json.parse(json).ATLAS; + + for (sprite in data.SPRITES) + { + // probably nicer way to do this? Oh well + var swagSprite:AnimateSprite = sprite.SPRITE; + + var rect = FlxRect.get(swagSprite.x, swagSprite.y, swagSprite.w, swagSprite.h); + + var size = new Rectangle(0, 0, rect.width, rect.height); + + var offset = FlxPoint.get(-size.left, -size.top); + var sourceSize = FlxPoint.get(size.width, size.height); + + frames.addAtlasFrame(rect, sourceSize, offset, swagSprite.name); + } + + return frames; + } +} + +typedef AnimateObject = +{ + SPRITES:Array +} + +typedef AnimateSprite = +{ + var name:String; + var x:Int; + var y:Int; + var w:Int; + var h:Int; + var rotated:Bool; +}