addAnim for FunkinSprite + better names
so u dont have to manually add based if atlas or sparrow or else this behaves as both addByPrefix and addByIndices and like the xml animations
This commit is contained in:
@@ -328,7 +328,31 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
|||||||
lastAnimContext = Context;
|
lastAnimContext = Context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAnim(name:String):OneOfTwo<FlxAnimation, FlxSymbolAnimation> {
|
public inline function addAnim(name:String, prefix:String, frameRate:Float = 24, ?looped:Bool, ?forced:Bool, ?indices:Array<Int>, x:Float = 0, y:Float = 0, animType:XMLAnimType = NONE)
|
||||||
|
{
|
||||||
|
return XMLUtil.addAnimToSprite(this, {
|
||||||
|
name: name,
|
||||||
|
anim: prefix,
|
||||||
|
fps: frameRate,
|
||||||
|
loop: looped == null ? animType == LOOP : looped,
|
||||||
|
animType: animType,
|
||||||
|
x: x,
|
||||||
|
y: y,
|
||||||
|
indices: indices,
|
||||||
|
forced: forced
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function removeAnim(name:String)
|
||||||
|
{
|
||||||
|
if (animateAtlas != null)
|
||||||
|
@:privateAccess animateAtlas.anim.animsMap.remove(name);
|
||||||
|
else
|
||||||
|
animation.remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAnim(name:String):OneOfTwo<FlxAnimation, FlxSymbolAnimation>
|
||||||
|
{
|
||||||
if(animateAtlas != null)
|
if(animateAtlas != null)
|
||||||
return animateAtlas.anim.getByName(name);
|
return animateAtlas.anim.getByName(name);
|
||||||
return animation.getByName(name);
|
return animation.getByName(name);
|
||||||
@@ -341,7 +365,7 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
|||||||
return FlxPoint.weak(0, 0);
|
return FlxPoint.weak(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function hasAnimation(AnimName:String):Bool @:privateAccess
|
public inline function hasAnim(AnimName:String):Bool @:privateAccess
|
||||||
return animateAtlas != null ? (animateAtlas.anim.animsMap.exists(AnimName)
|
return animateAtlas != null ? (animateAtlas.anim.animsMap.exists(AnimName)
|
||||||
|| animateAtlas.anim.symbolDictionary.exists(AnimName)) : animation.exists(AnimName);
|
|| animateAtlas.anim.symbolDictionary.exists(AnimName)) : animation.exists(AnimName);
|
||||||
|
|
||||||
@@ -364,13 +388,6 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
|||||||
return animateAtlas != null ? animateAtlas.anim.reversed : animation.curAnim != null ? animation.curAnim.reversed : false;
|
return animateAtlas != null ? animateAtlas.anim.reversed : animation.curAnim != null ? animation.curAnim.reversed : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function removeAnimation(name:String) {
|
|
||||||
if (animateAtlas != null)
|
|
||||||
@:privateAccess animateAtlas.anim.animsMap.remove(name);
|
|
||||||
else
|
|
||||||
animation.remove(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public inline function getNameList():Array<String> {
|
public inline function getNameList():Array<String> {
|
||||||
if (animateAtlas != null)
|
if (animateAtlas != null)
|
||||||
return [for (name in @:privateAccess animateAtlas.anim.animsMap.keys()) name];
|
return [for (name in @:privateAccess animateAtlas.anim.animsMap.keys()) name];
|
||||||
@@ -378,7 +395,8 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
|||||||
return animation.getNameList();
|
return animation.getNameList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function stopAnimation() {
|
public inline function stopAnim()
|
||||||
|
{
|
||||||
if (animateAtlas != null)
|
if (animateAtlas != null)
|
||||||
animateAtlas.anim.pause();
|
animateAtlas.anim.pause();
|
||||||
else
|
else
|
||||||
@@ -393,6 +411,11 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
|||||||
public inline function isAnimAtEnd() {
|
public inline function isAnimAtEnd() {
|
||||||
return animateAtlas != null ? animateAtlas.anim.isAtEnd : (animation.curAnim != null ? animation.curAnim.isAtEnd : false);
|
return animateAtlas != null ? animateAtlas.anim.isAtEnd : (animation.curAnim != null ? animation.curAnim.isAtEnd : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backwards compat (the names used to be all different and it sucked, please lets use the same format in the future) - Nex
|
||||||
|
public inline function hasAnimation(AnimName:String) return hasAnim(AnimName);
|
||||||
|
public inline function removeAnimation(name:String) return removeAnim(name);
|
||||||
|
public inline function stopAnimation() return stopAnim();
|
||||||
#end
|
#end
|
||||||
|
|
||||||
// Getter / Setters
|
// Getter / Setters
|
||||||
|
|||||||
@@ -164,19 +164,17 @@ class XMLUtil {
|
|||||||
if(node.hasNode.anim) {
|
if(node.hasNode.anim) {
|
||||||
for(anim in node.nodes.anim)
|
for(anim in node.nodes.anim)
|
||||||
addXMLAnimation(spr, anim);
|
addXMLAnimation(spr, anim);
|
||||||
} else {
|
} else if (spr.frames != null && spr.frames.frames != null) {
|
||||||
if (spr.frames != null && spr.frames.frames != null) {
|
addAnimToSprite(spr, {
|
||||||
addAnimToSprite(spr, {
|
name: "idle",
|
||||||
name: "idle",
|
anim: null,
|
||||||
anim: null,
|
fps: 24,
|
||||||
fps: 24,
|
loop: spr.spriteAnimType == LOOP,
|
||||||
loop: spr.spriteAnimType == LOOP,
|
animType: spr.spriteAnimType,
|
||||||
animType: spr.spriteAnimType,
|
x: 0,
|
||||||
x: 0,
|
y: 0,
|
||||||
y: 0,
|
indices: [for(i in 0...spr.frames.frames.length) i]
|
||||||
indices: [for(i in 0...spr.frames.frames.length) i]
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return spr;
|
return spr;
|
||||||
@@ -238,16 +236,17 @@ class XMLUtil {
|
|||||||
if(animData.anim == null)
|
if(animData.anim == null)
|
||||||
return MISSING_PROPERTY;
|
return MISSING_PROPERTY;
|
||||||
|
|
||||||
if (animData.indices.length > 0)
|
if (animData.indices != null && animData.indices.length > 0)
|
||||||
animateAnim.addBySymbolIndices(animData.name, animData.anim, animData.indices, animData.fps, animData.loop);
|
animateAnim.addBySymbolIndices(animData.name, animData.anim, animData.indices, animData.fps, animData.loop);
|
||||||
else
|
else
|
||||||
animateAnim.addBySymbol(animData.name, animData.anim, animData.fps, animData.loop);
|
animateAnim.addBySymbol(animData.name, animData.anim, animData.fps, animData.loop);
|
||||||
} else {
|
} else {
|
||||||
if (animData.anim == null && animData.indices.length > 0)
|
if (animData.indices != null && animData.indices.length > 0) {
|
||||||
sprite.animation.add(animData.name, animData.indices, animData.fps, animData.loop);
|
if (animData.anim == null)
|
||||||
else if (animData.indices.length > 0)
|
sprite.animation.add(animData.name, animData.indices, animData.fps, animData.loop);
|
||||||
sprite.animation.addByIndices(animData.name, animData.anim, animData.indices, "", animData.fps, animData.loop);
|
else
|
||||||
else
|
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);
|
sprite.animation.addByPrefix(animData.name, animData.anim, animData.fps, animData.loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user