2022-04-18 23:36:09 +00:00
|
|
|
package funkin.util.assets;
|
|
|
|
|
|
|
|
import flixel.FlxSprite;
|
2022-11-15 07:23:44 +00:00
|
|
|
import flixel.graphics.frames.FlxFramesCollection;
|
2023-07-14 00:25:01 +00:00
|
|
|
import funkin.data.animation.AnimationData;
|
2022-04-18 23:36:09 +00:00
|
|
|
|
|
|
|
class FlxAnimationUtil
|
|
|
|
{
|
2023-01-23 03:25:45 +00:00
|
|
|
/**
|
2023-07-14 00:25:01 +00:00
|
|
|
* Properly adds an animation to a sprite based on the provided animation data.
|
2023-01-23 03:25:45 +00:00
|
|
|
*/
|
|
|
|
public static function addAtlasAnimation(target:FlxSprite, anim:AnimationData)
|
|
|
|
{
|
|
|
|
var frameRate = anim.frameRate == null ? 24 : anim.frameRate;
|
|
|
|
var looped = anim.looped == null ? false : anim.looped;
|
|
|
|
var flipX = anim.flipX == null ? false : anim.flipX;
|
|
|
|
var flipY = anim.flipY == null ? false : anim.flipY;
|
2022-04-18 23:36:09 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
if (anim.frameIndices != null && anim.frameIndices.length > 0)
|
|
|
|
{
|
|
|
|
// trace('addByIndices(${anim.name}, ${anim.prefix}, ${anim.frameIndices}, ${frameRate}, ${looped}, ${flipX}, ${flipY})');
|
2023-08-22 08:27:30 +00:00
|
|
|
target.animation.addByIndices(anim.name, anim.prefix, anim.frameIndices, '', frameRate, looped, flipX, flipY);
|
2023-01-23 03:25:45 +00:00
|
|
|
// trace('RESULT:${target.animation.getAnimationList()}');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// trace('addByPrefix(${anim.name}, ${anim.prefix}, ${frameRate}, ${looped}, ${flipX}, ${flipY})');
|
|
|
|
target.animation.addByPrefix(anim.name, anim.prefix, frameRate, looped, flipX, flipY);
|
|
|
|
// trace('RESULT:${target.animation.getAnimationList()}');
|
|
|
|
}
|
|
|
|
}
|
2022-04-18 23:36:09 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
/**
|
2023-07-14 00:25:01 +00:00
|
|
|
* Properly adds multiple animations to a sprite based on the provided animation data.
|
2023-01-23 03:25:45 +00:00
|
|
|
*/
|
|
|
|
public static function addAtlasAnimations(target:FlxSprite, animations:Array<AnimationData>)
|
|
|
|
{
|
|
|
|
for (anim in animations)
|
|
|
|
{
|
|
|
|
addAtlasAnimation(target, anim);
|
|
|
|
}
|
|
|
|
}
|
2022-11-15 07:23:44 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
public static function combineFramesCollections(a:FlxFramesCollection, b:FlxFramesCollection):FlxFramesCollection
|
|
|
|
{
|
|
|
|
var result:FlxFramesCollection = new FlxFramesCollection(null, ATLAS, null);
|
2022-11-15 07:23:44 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
for (frame in a.frames)
|
|
|
|
{
|
|
|
|
result.pushFrame(frame);
|
|
|
|
}
|
|
|
|
for (frame in b.frames)
|
|
|
|
{
|
|
|
|
result.pushFrame(frame);
|
|
|
|
}
|
2022-11-15 07:23:44 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
return result;
|
|
|
|
}
|
2022-04-18 23:36:09 +00:00
|
|
|
}
|