From 8524f244c752fd130089964b782ab3d58daa11d1 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Wed, 14 Apr 2021 11:31:52 -0400 Subject: [PATCH 1/2] animation rotations --- source/CoolUtil.hx | 1 + source/CutsceneAnimTestState.hx | 16 +- source/TitleState.hx | 2 + source/animate/FlxAnimate.hx | 73 +++----- source/animate/FlxSymbol.hx | 283 ++++++++++++++++++++++++++++++++ 5 files changed, 310 insertions(+), 65 deletions(-) create mode 100644 source/animate/FlxSymbol.hx diff --git a/source/CoolUtil.hx b/source/CoolUtil.hx index 3ec3cf1e1..3b0ce0372 100644 --- a/source/CoolUtil.hx +++ b/source/CoolUtil.hx @@ -3,6 +3,7 @@ package; import flixel.FlxG; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxAtlasFrames; +import flixel.math.FlxMath; import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.system.FlxAssets.FlxGraphicAsset; diff --git a/source/CutsceneAnimTestState.hx b/source/CutsceneAnimTestState.hx index 32d9cd3eb..8e83e1107 100644 --- a/source/CutsceneAnimTestState.hx +++ b/source/CutsceneAnimTestState.hx @@ -1,8 +1,6 @@ package; import animate.FlxAnimate; -import animateAtlasPlayer.assets.AssetManager; -import animateAtlasPlayer.core.Animation; import flixel.FlxG; import flixel.FlxSprite; import flixel.FlxState; @@ -13,18 +11,10 @@ import flixel.text.FlxText; import flixel.util.FlxColor; import openfl.display.BitmapData; +// import animateAtlasPlayer.assets.AssetManager; +// import animateAtlasPlayer.core.Animation; class CutsceneAnimTestState extends FlxState { - var animShit:Array = [ - 'GF STARTS TO TURN PART 1', - 'GF STARTS TO TURN PART 2', - 'PICO ARRIVES PART 1', - 'PICO ARRIVES PART 2', - 'PICO ARRIVES PART 2 POINT FIVE', - 'PICO ARRIVES PART 3', - 'Pico Dual Wield on Speaker' - ]; - var cutsceneGroup:CutsceneCharacter; var curSelected:Int = 0; @@ -42,7 +32,7 @@ class CutsceneAnimTestState extends FlxState debugTxt.color = FlxColor.BLUE; add(debugTxt); - var animated:FlxAnimate = new FlxAnimate(10, 10); + var animated:FlxAnimate = new FlxAnimate(600, 200); add(animated); // createCutscene(0); diff --git a/source/TitleState.hx b/source/TitleState.hx index 8f052a791..189639df3 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -107,6 +107,8 @@ class TitleState extends MusicBeatState #if FREEPLAY FlxG.switchState(new FreeplayState()); + #elseif ANIMATE + FlxG.switchState(new CutsceneAnimTestState()); #elseif CHARTING FlxG.switchState(new ChartingState()); /* diff --git a/source/animate/FlxAnimate.hx b/source/animate/FlxAnimate.hx index bdcb95730..a99e203d6 100644 --- a/source/animate/FlxAnimate.hx +++ b/source/animate/FlxAnimate.hx @@ -1,7 +1,8 @@ package animate; -import animateAtlasPlayer.assets.AssetManager; -import animateAtlasPlayer.core.Animation; +// import animateAtlasPlayer.assets.AssetManager; +// import animateAtlasPlayer.core.Animation; +import animate.FlxSymbol.Parsed; import flixel.FlxG; import flixel.FlxSprite; import flixel.graphics.FlxGraphic; @@ -11,75 +12,43 @@ 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 +class FlxAnimate extends FlxSymbol { - var myAnim:Animation; - var animBitmap:BitmapData; - + // var myAnim:Animation; + // var animBitmap:BitmapData; var loadedQueue:Bool = false; var swagFrames:Array = []; public function new(x:Float, y:Float) { - super(x, y); + var folder:String = 'tightBars'; + coolParse = cast Json.parse(Assets.getText(Paths.file('images/' + folder + '/Animation.json'))); + coolParse.AN.TL.L.reverse(); + super(x, y, coolParse); - // 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; - }); + frames = FlxAnimate.fromAnimate(Paths.file('images/' + folder + '/spritemap1.png'), Paths.file('images/' + folder + '/spritemap1.json')); + // frames } - 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); + renderFrame(coolParse.AN.TL, coolParse, true); + } - animBitmap.draw(myAnim); - } + var curFrame:Int = 0; - // animBitmap.draw(myAnim); - } + // notes to self + // account for different layers + + override function update(elapsed:Float) + { + super.update(elapsed); } // This stuff is u diff --git a/source/animate/FlxSymbol.hx b/source/animate/FlxSymbol.hx new file mode 100644 index 000000000..8123721d4 --- /dev/null +++ b/source/animate/FlxSymbol.hx @@ -0,0 +1,283 @@ +package animate; + +import flixel.FlxSprite; +import flixel.math.FlxAngle; + +class FlxSymbol extends FlxSprite +{ + public var coolParse:Parsed; + public var oldMatrix:Array = []; + + public function new(x:Float, y:Float, coolParsed:Parsed) + { + super(x, y); + + this.coolParse = coolParsed; + + var hasSymbolDictionary:Bool = Reflect.hasField(coolParse, "SD"); + + if (hasSymbolDictionary) + symbolAtlasShit = parseSymbolDictionary(coolParse); + } + + var symbolAtlasShit:Map = new Map(); + + override function draw() + { + super.draw(); + } + + var swagX:Float = 0; + var swagY:Float = 0; + + var symbolMap:Map = new Map(); + + var drawQueue:Array = []; + + function renderFrame(TL:Timeline, coolParsed:Parsed, ?isMainLoop:Bool = false) + { + drawQueue = []; + + for (layer in TL.L) + { + var frameInfo:Frame = layer.FR[0]; + + if (isMainLoop) + frameInfo = layer.FR[0]; + + // frameInfo.E.reverse(); + + for (element in frameInfo.E) + { + if (Reflect.hasField(element, 'ASI')) + { + var spr:FlxSymbol = new FlxSymbol(x + element.ASI.M3D[12], y + element.ASI.M3D[13], coolParsed); + + if (oldMatrix != null) + { + // spr.x += oldMatrix[12]; + // spr.y += oldMatrix[13]; + } + // trace(element.ASI.M3D[12] + element.ASI.N); + + spr.frames = frames; + // spr.animation.addByPrefix('swag',) + + spr.frame = spr.frames.getByName(element.ASI.N); + + // spr.flipX = true; + + var m3d = element.ASI.M3D; + _matrix.identity(); + _matrix.setTo(m3d[0], m3d[1], m3d[4], m3d[5], m3d[12], m3d[13]); + + // spr.scale.x = m3d[0]; + spr.scale.y = Math.sqrt(_matrix.c * _matrix.c + _matrix.d * _matrix.d); + spr.scale.x = Math.sqrt(_matrix.a * _matrix.a + _matrix.b * _matrix.b); + spr.origin.set(); + spr.origin.x += origin.x; + spr.origin.y += origin.y; + spr.angle = FlxAngle.asDegrees(Math.atan2(m3d[1], m3d[0])) + angle; + spr.antialiasing = true; + + // spr.scale.y = m3d[5]; + + // if (flipX || m3d[0] == -1) + // spr.flipX = true; + + // _matrix.identity(); + + // _matrix.setTo(m3d[0], m3d[1], m3d[4], m3d[5], m3d[12], m3d[13]); + // spr.x = _matrix.tx + swagX; + // spr.y = _matrix.ty + swagY; + + // spr._matrix.setTo(m3d[0], m3d[1], m3d[4], m3d[5], m3d[12], m3d[13]); + + drawQueue.push(spr); + // spr.draw(); + + // swagX = 0; + } + else + { + var nestedSymbol = symbolMap.get(element.SI.SN); + // trace(element.SI.M3D[12]); + // swagX = x +; + // swagY =; + + if (oldMatrix != null) + { + // x += oldMatrix[12]; + // y += oldMatrix[13]; + } + + // if (symbolAtlasShit.exists(nestedSymbol.SN)) + // { + // nestedShit.frames.getByName(symbolAtlasShit.get(nestedSymbol.SN)); + // nestedShit.draw(); + // } + + // nestedSymbol + + // if (element.SI.M3D[0] == -1 || flipX) + // nestedShit.flipX = true; + + // nestedSymbol.TL.L.reverse(); + + _matrix.identity(); + _matrix.setTo(element.SI.M3D[0], element.SI.M3D[1], element.SI.M3D[4], element.SI.M3D[5], element.SI.M3D[12], element.SI.M3D[13]); + // _matrix.scale(1, 1); + + var nestedShit:FlxSymbol = new FlxSymbol(x + _matrix.tx, y + _matrix.ty, coolParse); + nestedShit.frames = frames; + + nestedShit.scale.x = Math.sqrt(_matrix.a * _matrix.a + _matrix.b + _matrix.b); + nestedShit.scale.y = Math.sqrt(_matrix.a * _matrix.a + _matrix.b * _matrix.b); + nestedShit.origin.set(element.SI.TRP.x, element.SI.TRP.y); + + nestedShit.angle = FlxAngle.asDegrees(Math.atan2(_matrix.b, _matrix.a)); + + // scale.y = Math.sqrt(_matrix.c * _matrix.c + _matrix.d * _matrix.d); + // scale.x = Math.sqrt(_matrix.a * _matrix.a + _matrix.b * _matrix.b); + + // nestedShit.oldMatrix = element.SI.M3D; + + nestedShit.renderFrame(nestedSymbol.TL, coolParsed); + + // renderFrame(nestedSymbol.TL, coolParsed); + } + } + } + + // drawQueue.reverse(); + // + for (thing in drawQueue) + thing.draw(); + } + + function parseSymbolDictionary(coolParsed:Parsed):Map + { + var awesomeMap:Map = new Map(); + for (symbol in coolParsed.SD.S) + { + symbolMap.set(symbol.SN, symbol); + + var symbolName = symbol.SN; + for (layer in symbol.TL.L) + { + for (frame in layer.FR) + { + for (element in frame.E) + { + if (Reflect.hasField(element, 'ASI')) + { + awesomeMap.set(symbolName, element.ASI.N); + } + } + } + } + } + + return awesomeMap; + } +} + +// TYPEDEFS FOR ANIMATION.JSON PARSING + +typedef Parsed = +{ + var MD:Metadata; + var AN:Animation; + var SD:SymbolDictionary; // Doesn't always have symbol dictionary!! +} + +typedef Metadata = +{ + /** Framerate */ + var FRT:Int; +} + +/** Basically treated like one big symbol*/ +typedef Animation = +{ + /** symbolName */ + var SN:String; + + var TL:Timeline; + + /** IDK what STI stands for, Symbole Type Instance? + Anyways, it is NOT used in SYMBOLS, only the main AN animation + */ + var STI:Dynamic; +} + +/** DISCLAIMER, MAY NOT ACTUALLY BE CALLED + SYMBOL TYPE ISNTANCE, IM JUST MAKING ASSUMPTION!! */ +typedef SymbolTypeInstance = +{ + // var TL:Timeline; + // var SN:String; +} + +typedef SymbolDictionary = +{ + var S:Array; +} + +typedef Timeline = +{ + /** Layers */ + var L:Array; +} + +// Singular layer, not to be confused with LAYERS +typedef Layer = +{ + var LN:String; + + /** Frames */ + var FR:Array; +} + +typedef Frame = +{ + var I:Int; + + /** Duration, in frames*/ + var DU:Int; + + /** Elements*/ + var E:Array; +} + +typedef Element = +{ + var SI:SymbolInstance; + var ASI:AtlasSymbolInstance; +} + +/** + Symbol instance, for SYMBOLS and refers to SYMBOLS + */ +typedef SymbolInstance = +{ + var SN:String; + + /** SymbolType (Graphic, Movieclip, Button)*/ + var ST:String; + + var TRP:TransformationPoint; + var M3D:Array; +} + +typedef AtlasSymbolInstance = +{ + var N:String; + var M3D:Array; +} + +typedef TransformationPoint = +{ + var x:Float; + var y:Float; +} From 75c1cbdbd3787a4ca357791411e333e3f410fc8c Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Wed, 14 Apr 2021 21:52:43 -0400 Subject: [PATCH 2/2] animation playback wip --- source/animate/FlxAnimate.hx | 23 ++++ source/animate/FlxSymbol.hx | 203 ++++++++++++++++++----------------- 2 files changed, 126 insertions(+), 100 deletions(-) diff --git a/source/animate/FlxAnimate.hx b/source/animate/FlxAnimate.hx index a99e203d6..16d6ba022 100644 --- a/source/animate/FlxAnimate.hx +++ b/source/animate/FlxAnimate.hx @@ -45,10 +45,33 @@ class FlxAnimate extends FlxSymbol // notes to self // account for different layers + var playingAnim:Bool = false; + var frameTickTypeShit:Float = 0; + var animFrameRate:Int = 24; override function update(elapsed:Float) { super.update(elapsed); + + if (FlxG.keys.justPressed.SPACE) + playingAnim = !playingAnim; + + if (playingAnim) + { + frameTickTypeShit += elapsed; + + // prob fix this framerate thing for higher framerates? + if (frameTickTypeShit >= 1 / 24) + { + changeFrame(1); + frameTickTypeShit = 0; + } + } + + if (FlxG.keys.justPressed.RIGHT) + changeFrame(1); + if (FlxG.keys.justPressed.LEFT) + changeFrame(-1); } // This stuff is u diff --git a/source/animate/FlxSymbol.hx b/source/animate/FlxSymbol.hx index 8123721d4..ff3ac5ab7 100644 --- a/source/animate/FlxSymbol.hx +++ b/source/animate/FlxSymbol.hx @@ -8,6 +8,8 @@ class FlxSymbol extends FlxSprite public var coolParse:Parsed; public var oldMatrix:Array = []; + private var hasFrameByPass:Bool = false; + public function new(x:Float, y:Float, coolParsed:Parsed) { super(x, y); @@ -34,117 +36,113 @@ class FlxSymbol extends FlxSprite var drawQueue:Array = []; + public var daFrame:Int = 0; + function renderFrame(TL:Timeline, coolParsed:Parsed, ?isMainLoop:Bool = false) { drawQueue = []; for (layer in TL.L) { - var frameInfo:Frame = layer.FR[0]; + // layer.FR.reverse(); + // var frame = layer.FR[0] - if (isMainLoop) - frameInfo = layer.FR[0]; - - // frameInfo.E.reverse(); - - for (element in frameInfo.E) + for (frame in layer.FR) { - if (Reflect.hasField(element, 'ASI')) + if (daFrame >= frame.I && daFrame < frame.I + frame.DU) { - var spr:FlxSymbol = new FlxSymbol(x + element.ASI.M3D[12], y + element.ASI.M3D[13], coolParsed); - - if (oldMatrix != null) + for (element in frame.E) { - // spr.x += oldMatrix[12]; - // spr.y += oldMatrix[13]; + if (Reflect.hasField(element, 'ASI')) + { + var spr:FlxSymbol = new FlxSymbol(x + element.ASI.M3D[12], y + element.ASI.M3D[13], coolParsed); + + if (oldMatrix != null) + { + // spr.x += oldMatrix[12]; + // spr.y += oldMatrix[13]; + } + // trace(element.ASI.M3D[12] + element.ASI.N); + + spr.frames = frames; + // spr.animation.addByPrefix('swag',) + + spr.frame = spr.frames.getByName(element.ASI.N); + + // spr.flipX = true; + + var m3d = element.ASI.M3D; + _matrix.identity(); + _matrix.setTo(m3d[0], m3d[1], m3d[4], m3d[5], m3d[12], m3d[13]); + + // spr.scale.x = m3d[0]; + spr.scale.y = Math.sqrt(_matrix.c * _matrix.c + _matrix.d * _matrix.d); + spr.scale.x = Math.sqrt(_matrix.a * _matrix.a + _matrix.b * _matrix.b); + spr.origin.set(); + spr.origin.x += origin.x; + spr.origin.y += origin.y; + spr.angle = FlxAngle.asDegrees(Math.atan2(m3d[1], m3d[0])) + angle; + spr.antialiasing = true; + + // spr.scale.y = m3d[5]; + + // if (flipX || m3d[0] == -1) + // spr.flipX = true; + + // _matrix.identity(); + + // _matrix.setTo(m3d[0], m3d[1], m3d[4], m3d[5], m3d[12], m3d[13]); + // spr.x = _matrix.tx + swagX; + // spr.y = _matrix.ty + swagY; + + // spr._matrix.setTo(m3d[0], m3d[1], m3d[4], m3d[5], m3d[12], m3d[13]); + + drawQueue.push(spr); + // spr.draw(); + + // swagX = 0; + } + else + { + var nestedSymbol = symbolMap.get(element.SI.SN); + + // nestedSymbol + + // if (element.SI.M3D[0] == -1 || flipX) + // nestedShit.flipX = true; + + // nestedSymbol.TL.L.reverse(); + + _matrix.identity(); + _matrix.setTo(element.SI.M3D[0], element.SI.M3D[1], element.SI.M3D[4], element.SI.M3D[5], element.SI.M3D[12], element.SI.M3D[13]); + // _matrix.scale(1, 1); + + var nestedShit:FlxSymbol = new FlxSymbol(x + _matrix.tx, y + _matrix.ty, coolParse); + nestedShit.frames = frames; + + nestedShit.scale.x = Math.sqrt(_matrix.a * _matrix.a + _matrix.b + _matrix.b); + nestedShit.scale.y = Math.sqrt(_matrix.a * _matrix.a + _matrix.b * _matrix.b); + nestedShit.origin.set(element.SI.TRP.x, element.SI.TRP.y); + + nestedShit.angle = FlxAngle.asDegrees(Math.atan2(_matrix.b, _matrix.a)); + + if (symbolAtlasShit.exists(nestedSymbol.SN)) + { + // nestedShit.frames.getByName(symbolAtlasShit.get(nestedSymbol.SN)); + // nestedShit.draw(); + } + + // scale.y = Math.sqrt(_matrix.c * _matrix.c + _matrix.d * _matrix.d); + // scale.x = Math.sqrt(_matrix.a * _matrix.a + _matrix.b * _matrix.b); + + // nestedShit.oldMatrix = element.SI.M3D; + + nestedShit.hasFrameByPass = true; + nestedShit.renderFrame(nestedSymbol.TL, coolParsed); + + // renderFrame(nestedSymbol.TL, coolParsed); + } } - // trace(element.ASI.M3D[12] + element.ASI.N); - - spr.frames = frames; - // spr.animation.addByPrefix('swag',) - - spr.frame = spr.frames.getByName(element.ASI.N); - - // spr.flipX = true; - - var m3d = element.ASI.M3D; - _matrix.identity(); - _matrix.setTo(m3d[0], m3d[1], m3d[4], m3d[5], m3d[12], m3d[13]); - - // spr.scale.x = m3d[0]; - spr.scale.y = Math.sqrt(_matrix.c * _matrix.c + _matrix.d * _matrix.d); - spr.scale.x = Math.sqrt(_matrix.a * _matrix.a + _matrix.b * _matrix.b); - spr.origin.set(); - spr.origin.x += origin.x; - spr.origin.y += origin.y; - spr.angle = FlxAngle.asDegrees(Math.atan2(m3d[1], m3d[0])) + angle; - spr.antialiasing = true; - - // spr.scale.y = m3d[5]; - - // if (flipX || m3d[0] == -1) - // spr.flipX = true; - - // _matrix.identity(); - - // _matrix.setTo(m3d[0], m3d[1], m3d[4], m3d[5], m3d[12], m3d[13]); - // spr.x = _matrix.tx + swagX; - // spr.y = _matrix.ty + swagY; - - // spr._matrix.setTo(m3d[0], m3d[1], m3d[4], m3d[5], m3d[12], m3d[13]); - - drawQueue.push(spr); - // spr.draw(); - - // swagX = 0; - } - else - { - var nestedSymbol = symbolMap.get(element.SI.SN); - // trace(element.SI.M3D[12]); - // swagX = x +; - // swagY =; - - if (oldMatrix != null) - { - // x += oldMatrix[12]; - // y += oldMatrix[13]; - } - - // if (symbolAtlasShit.exists(nestedSymbol.SN)) - // { - // nestedShit.frames.getByName(symbolAtlasShit.get(nestedSymbol.SN)); - // nestedShit.draw(); - // } - - // nestedSymbol - - // if (element.SI.M3D[0] == -1 || flipX) - // nestedShit.flipX = true; - - // nestedSymbol.TL.L.reverse(); - - _matrix.identity(); - _matrix.setTo(element.SI.M3D[0], element.SI.M3D[1], element.SI.M3D[4], element.SI.M3D[5], element.SI.M3D[12], element.SI.M3D[13]); - // _matrix.scale(1, 1); - - var nestedShit:FlxSymbol = new FlxSymbol(x + _matrix.tx, y + _matrix.ty, coolParse); - nestedShit.frames = frames; - - nestedShit.scale.x = Math.sqrt(_matrix.a * _matrix.a + _matrix.b + _matrix.b); - nestedShit.scale.y = Math.sqrt(_matrix.a * _matrix.a + _matrix.b * _matrix.b); - nestedShit.origin.set(element.SI.TRP.x, element.SI.TRP.y); - - nestedShit.angle = FlxAngle.asDegrees(Math.atan2(_matrix.b, _matrix.a)); - - // scale.y = Math.sqrt(_matrix.c * _matrix.c + _matrix.d * _matrix.d); - // scale.x = Math.sqrt(_matrix.a * _matrix.a + _matrix.b * _matrix.b); - - // nestedShit.oldMatrix = element.SI.M3D; - - nestedShit.renderFrame(nestedSymbol.TL, coolParsed); - - // renderFrame(nestedSymbol.TL, coolParsed); } } } @@ -155,6 +153,11 @@ class FlxSymbol extends FlxSprite thing.draw(); } + function changeFrame(frameChange:Int = 0):Void + { + daFrame += frameChange; + } + function parseSymbolDictionary(coolParsed:Parsed):Map { var awesomeMap:Map = new Map();