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
Binary file not shown.
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,46 @@
{"ATLAS": {"SPRITES":[
{"SPRITE" : {"name": "0000","x":729,"y":358,"w":287,"h":360,"rotated": false}},
{"SPRITE" : {"name": "0001","x":420,"y":358,"w":309,"h":375,"rotated": false}},
{"SPRITE" : {"name": "0002","x":0,"y":0,"w":420,"h":359,"rotated": false}},
{"SPRITE" : {"name": "0003","x":420,"y":0,"w":406,"h":358,"rotated": false}},
{"SPRITE" : {"name": "0004","x":0,"y":359,"w":336,"h":165,"rotated": false}},
{"SPRITE" : {"name": "0005","x":934,"y":217,"w":90,"h":103,"rotated": false}},
{"SPRITE" : {"name": "0006","x":0,"y":524,"w":215,"h":242,"rotated": false}},
{"SPRITE" : {"name": "0007","x":729,"y":718,"w":213,"h":240,"rotated": false}},
{"SPRITE" : {"name": "0008","x":826,"y":0,"w":191,"h":120,"rotated": false}},
{"SPRITE" : {"name": "0009","x":565,"y":733,"w":90,"h":151,"rotated": false}},
{"SPRITE" : {"name": "0010","x":215,"y":733,"w":258,"h":124,"rotated": false}},
{"SPRITE" : {"name": "0011","x":372,"y":882,"w":122,"h":67,"rotated": false}},
{"SPRITE" : {"name": "0012","x":826,"y":217,"w":108,"h":126,"rotated": false}},
{"SPRITE" : {"name": "0013","x":215,"y":524,"w":103,"h":149,"rotated": false}},
{"SPRITE" : {"name": "0014","x":0,"y":766,"w":95,"h":130,"rotated": false}},
{"SPRITE" : {"name": "0015","x":1017,"y":0,"w":1,"h":4,"rotated": false}},
{"SPRITE" : {"name": "0016","x":942,"y":823,"w":67,"h":70,"rotated": false}},
{"SPRITE" : {"name": "0017","x":0,"y":924,"w":122,"h":62,"rotated": false}},
{"SPRITE" : {"name": "0018","x":336,"y":359,"w":64,"h":106,"rotated": false}},
{"SPRITE" : {"name": "0019","x":655,"y":733,"w":55,"h":112,"rotated": false}},
{"SPRITE" : {"name": "0020","x":274,"y":857,"w":98,"h":118,"rotated": false}},
{"SPRITE" : {"name": "0021","x":942,"y":718,"w":59,"h":105,"rotated": false}},
{"SPRITE" : {"name": "0022","x":318,"y":524,"w":87,"h":160,"rotated": false}},
{"SPRITE" : {"name": "0023","x":473,"y":733,"w":92,"h":149,"rotated": false}},
{"SPRITE" : {"name": "0024","x":215,"y":684,"w":104,"h":42,"rotated": false}},
{"SPRITE" : {"name": "0025","x":934,"y":340,"w":73,"h":18,"rotated": false}},
{"SPRITE" : {"name": "0026","x":336,"y":465,"w":72,"h":19,"rotated": false}},
{"SPRITE" : {"name": "0027","x":336,"y":484,"w":72,"h":18,"rotated": false}},
{"SPRITE" : {"name": "0028","x":934,"y":320,"w":73,"h":20,"rotated": false}},
{"SPRITE" : {"name": "0029","x":95,"y":857,"w":179,"h":67,"rotated": false}},
{"SPRITE" : {"name": "0030","x":95,"y":766,"w":118,"h":75,"rotated": false}},
{"SPRITE" : {"name": "0031","x":494,"y":884,"w":128,"h":61,"rotated": false}},
{"SPRITE" : {"name": "0032","x":122,"y":924,"w":124,"h":58,"rotated": false}},
{"SPRITE" : {"name": "0033","x":826,"y":120,"w":174,"h":97,"rotated": false}},
{"SPRITE" : {"name": "0034","x":826,"y":343,"w":82,"h":14,"rotated": false}}
]},
"meta": {
"app": "Adobe Animate",
"version": "21.0.1.37179",
"image": "spritemap1.png",
"format": "RGBA8888",
"size": {"w":1024,"h":986},
"resolution": "1"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

+1 -1
View File
@@ -1 +1 @@
1903
1913
+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);