xml sprites?????????????????????????????
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package funkin.system;
|
||||
|
||||
import flixel.math.FlxMatrix;
|
||||
import flixel.math.FlxRect;
|
||||
import flixel.math.FlxPoint;
|
||||
import flixel.FlxCamera;
|
||||
import flixel.math.FlxMath;
|
||||
import funkin.interfaces.IBeatReceiver;
|
||||
import flixel.FlxSprite;
|
||||
|
||||
class XMLSprite extends FlxSprite implements IBeatReceiver {
|
||||
public var beatAnims:Array<String> = [];
|
||||
public var name:String;
|
||||
public var zoomFactor:Float = 1;
|
||||
public var initialZoom:Float = 1;
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
}
|
||||
|
||||
public function beatHit(curBeat:Int) {
|
||||
if (beatAnims.length > 0) {
|
||||
var anim = beatAnims[FlxMath.wrap(curBeat, 0, beatAnims.length-1)];
|
||||
if (anim != null && anim != "null" && anim != "none")
|
||||
animation.play(anim);
|
||||
}
|
||||
}
|
||||
public function stepHit(curBeat:Int) {}
|
||||
|
||||
public override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect {
|
||||
__doPreZoomScaleProcedure(camera);
|
||||
var r = super.getScreenBounds(newRect, camera);
|
||||
__doPostZoomScaleProcedure();
|
||||
return r;
|
||||
}
|
||||
public override function drawComplex(camera:FlxCamera) {
|
||||
super.drawComplex(camera);
|
||||
}
|
||||
|
||||
public override function doAdditionalMatrixStuff(matrix:FlxMatrix, camera:FlxCamera) {
|
||||
super.doAdditionalMatrixStuff(matrix, camera);
|
||||
matrix.translate(-camera.width / 2, -camera.height / 2);
|
||||
|
||||
var requestedZoom = FlxMath.lerp(1, camera.zoom, zoomFactor);
|
||||
var diff = requestedZoom / camera.zoom;
|
||||
matrix.scale(diff, diff);
|
||||
matrix.translate(camera.width / 2, camera.height / 2);
|
||||
}
|
||||
|
||||
public override function getScreenPosition(?point:FlxPoint, ?Camera:FlxCamera):FlxPoint {
|
||||
if (__shouldDoScaleProcedure()) {
|
||||
__oldScale = FlxPoint.get(scrollFactor.x, scrollFactor.y);
|
||||
var requestedZoom = FlxMath.lerp(initialZoom, camera.zoom, zoomFactor);
|
||||
var diff = requestedZoom / camera.zoom;
|
||||
|
||||
scrollFactor.scale(1/diff);
|
||||
|
||||
var r = super.getScreenPosition(point, Camera);
|
||||
|
||||
scrollFactor.set(__oldScale.x, __oldScale.y);
|
||||
__oldScale.put();
|
||||
__oldScale = null;
|
||||
|
||||
return r;
|
||||
}
|
||||
return super.getScreenPosition(point, Camera);
|
||||
}
|
||||
|
||||
// SCALING FUNCS
|
||||
#if REGION
|
||||
private inline function __shouldDoScaleProcedure()
|
||||
return zoomFactor != 1;
|
||||
|
||||
var __oldScale:FlxPoint;
|
||||
var __skipZoomProcedure:Bool = false;
|
||||
|
||||
private function __doPreZoomScaleProcedure(camera:FlxCamera) {
|
||||
if (__skipZoomProcedure = !__shouldDoScaleProcedure()) return;
|
||||
__oldScale = FlxPoint.get(scale.x, scale.y);
|
||||
var requestedZoom = FlxMath.lerp(initialZoom, camera.zoom, zoomFactor);
|
||||
var diff = requestedZoom / camera.zoom;
|
||||
|
||||
scale.scale(diff);
|
||||
}
|
||||
|
||||
private function __doPostZoomScaleProcedure() {
|
||||
if (__skipZoomProcedure) return;
|
||||
scale.set(__oldScale.x, __oldScale.y);
|
||||
__oldScale.put();
|
||||
__oldScale = null;
|
||||
}
|
||||
#end
|
||||
}
|
||||
@@ -77,6 +77,8 @@ class XMLUtil {
|
||||
}
|
||||
if (node.has.updateHitbox && node.att.updateHitbox == "true") spr.updateHitbox();
|
||||
|
||||
spr.zoomFactor = Std.parseFloat(node.getAtt("zoomfactor")).getDefault(spr.zoomFactor);
|
||||
|
||||
for(anim in node.nodes.anim)
|
||||
addXMLAnimation(spr, anim);
|
||||
|
||||
@@ -139,23 +141,4 @@ typedef AnimData = {
|
||||
var x:Float;
|
||||
var y:Float;
|
||||
var indices:Array<Int>;
|
||||
}
|
||||
|
||||
class XMLSprite extends FlxSprite implements IBeatReceiver {
|
||||
public var beatAnims:Array<String> = [];
|
||||
public var name:String;
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
}
|
||||
|
||||
public function beatHit(curBeat:Int) {
|
||||
if (beatAnims.length > 0) {
|
||||
var anim = beatAnims[FlxMath.wrap(curBeat, 0, beatAnims.length-1)];
|
||||
if (anim != null && anim != "null" && anim != "none")
|
||||
animation.play(anim);
|
||||
}
|
||||
|
||||
}
|
||||
public function stepHit(curBeat:Int) {}
|
||||
}
|
||||
Reference in New Issue
Block a user