texture atlas (gotta fix bugs with gf)

This commit is contained in:
Yoshman29
2023-01-06 20:25:03 +01:00
parent b05d4b6018
commit e37d8cfd39
9 changed files with 23105 additions and 13 deletions
+4 -4
View File
@@ -133,7 +133,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
if (xml.has.antialiasing) antialiasing = (xml.att.antialiasing == "true");
if (xml.has.sprite) sprite = xml.att.sprite;
frames = Paths.getFrames('characters/$sprite', null);
loadSprite(Paths.image('characters/$sprite'));
for(anim in xml.nodes.anim) {
XMLUtil.addXMLAnimation(this, anim);
}
@@ -170,7 +170,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
// flipX = true;
isDanceLeftDanceRight = (animation.getByName("danceLeft") != null && animation.getByName("danceRight") != null);
isDanceLeftDanceRight = (hasAnimation("danceLeft") && hasAnimation("danceRight"));
// alternative to xor operator
// for people who dont believe it, heres the truth table
@@ -241,10 +241,10 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
case DANCE:
dance();
case LOCK:
if (animation.curAnim == null)
if (getAnimName() == null)
dance();
default:
if (animation.curAnim == null || animation.curAnim.finished)
if (getAnimName() == null || isAnimFinished())
dance();
}
}
+2 -2
View File
@@ -286,7 +286,7 @@ class CoolUtil
return xml.att.resolve(name);
}
public static function loadFrames(path:String, Unique:Bool = false, Key:String = null):FlxFramesCollection {
public static function loadFrames(path:String, Unique:Bool = false, Key:String = null, SkipAtlasCheck:Bool = false):FlxFramesCollection {
var noExt = Path.withoutExtension(path);
if (Assets.exists('$noExt/1.png')) {
@@ -313,7 +313,7 @@ class CoolUtil
f.parent = frames.parent;
}
return finalFrames;
} else if (Assets.exists('$noExt/Animation.json')
} else if (!SkipAtlasCheck && Assets.exists('$noExt/Animation.json')
&& Assets.exists('$noExt/spritemap.json')
&& Assets.exists('$noExt/spritemap.png')) {
return AtlasFrameMaker.construct(noExt);
+77 -2
View File
@@ -1,5 +1,8 @@
package funkin.system;
import openfl.utils.Assets;
import flxanimate.FlxAnimate;
import haxe.io.Path;
import funkin.scripting.events.PlayAnimEvent.PlayAnimContext;
import funkin.interfaces.IOffsetCompatible;
import flixel.math.FlxMatrix;
@@ -33,8 +36,25 @@ class FunkinSprite extends FlxSprite implements IBeatReceiver implements IOffset
public var zoomFactor:Float = 1;
public var initialZoom:Float = 1;
public var animateAtlas:FlxAnimate;
@:noCompletion public var atlasPlayingAnim:String;
public override function update(elapsed:Float) {
super.update(elapsed);
if (animateAtlas != null)
animateAtlas.update(elapsed);
}
public function loadSprite(path:String, Unique:Bool = false, Key:String = null) {
var noExt = Path.withoutExtension(path);
if (Assets.exists('$noExt/Animation.json')
&& Assets.exists('$noExt/spritemap1.json')
&& Assets.exists('$noExt/spritemap1.png')) {
animateAtlas = new FlxAnimate(x, y, noExt);
}
else {
frames = CoolUtil.loadFrames(path, Unique, Key, true);
}
}
public function beatHit(curBeat:Int) {
@@ -85,6 +105,30 @@ class FunkinSprite extends FlxSprite implements IBeatReceiver implements IOffset
return super.getScreenPosition(point, Camera);
}
// ANIMATE ATLAS DRAWING
#if REGION
public override function draw() {
if (animateAtlas != null) {
copyAtlasValues();
animateAtlas.draw();
} else {
super.draw();
}
}
public function copyAtlasValues() {
@:privateAccess {
animateAtlas.cameras = cameras;
animateAtlas.scrollFactor = scrollFactor;
animateAtlas.offset = offset;
animateAtlas.rotOffset = rotOffset;
animateAtlas.x = x;
animateAtlas.y = y;
animateAtlas.antialiasing = antialiasing;
}
}
#end
// SCALING FUNCS
#if REGION
private inline function __shouldDoScaleProcedure()
@@ -130,9 +174,19 @@ class FunkinSprite extends FlxSprite implements IBeatReceiver implements IOffset
public var lastAnimContext:PlayAnimContext = DANCE;
public function playAnim(AnimName:String, Force:Bool = false, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0):Void
{
if (AnimName == null || !animation.exists(AnimName)) return;
if (AnimName == null) return;
animation.play(AnimName, Force, Reversed, Frame);
if (animateAtlas != null) {
@:privateAccess
//if (!animateAtlas.anim.animsMap.exists(AnimName) && !animateAtlas.anim.symbolDictionary.exists(AnimName)) return;
animateAtlas.anim.play(AnimName, Force, Reversed, Frame);
atlasPlayingAnim = AnimName;
}
else {
if (!animation.exists(AnimName)) return;
animation.play(AnimName, Force, Reversed, Frame);
}
var daOffset = getAnimOffset(AnimName);
rotOffset.set(daOffset.x, daOffset.y);
@@ -145,5 +199,26 @@ class FunkinSprite extends FlxSprite implements IBeatReceiver implements IOffset
return animOffsets[name];
return FlxPoint.weak(0, 0);
}
public inline function hasAnimation(AnimName:String):Bool
@:privateAccess
return animateAtlas != null
? (animateAtlas.anim.animsMap.exists(AnimName) || animateAtlas.anim.symbolDictionary.exists(AnimName))
: animation.getByName(AnimName) != null;
public inline function getAnimName() {
var name = null;
if (animateAtlas != null) {
name = atlasPlayingAnim;
} else {
if (animation.curAnim != null)
name = animation.curAnim.name;
}
return name;
}
public inline function isAnimFinished() {
return animateAtlas != null ? (animateAtlas.anim.finished) : (animation.curAnim != null ? animation.curAnim.finished : true);
}
#end
}
+12 -4
View File
@@ -137,10 +137,18 @@ class XMLUtil {
if (animData.name != null && animData.anim != null) {
if (animData.fps <= 0 #if web || animData.fps == null #end) animData.fps = 24;
if (animData.indices.length > 0)
sprite.animation.addByIndices(animData.name, animData.anim, animData.indices, "", animData.fps, animData.loop);
else
sprite.animation.addByPrefix(animData.name, animData.anim, animData.fps, animData.loop);
if (sprite is FunkinSprite && cast(sprite, FunkinSprite).animateAtlas != null) {
var animateAnim = cast(sprite, FunkinSprite).animateAtlas.anim;
if (animData.indices.length > 0)
animateAnim.addBySymbolIndices(animData.name, animData.anim, animData.indices, animData.fps, animData.loop);
else
animateAnim.addBySymbol(animData.name, animData.anim, animData.fps, animData.loop);
} else {
if (animData.indices.length > 0)
sprite.animation.addByIndices(animData.name, animData.anim, animData.indices, "", animData.fps, animData.loop);
else
sprite.animation.addByPrefix(animData.name, animData.anim, animData.fps, animData.loop);
}
if (sprite is IOffsetCompatible)
cast(sprite, IOffsetCompatible).addOffset(animData.name, animData.x, animData.y);