xml sprites?????????????????????????????
This commit is contained in:
@@ -58,6 +58,9 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
||||
if (!node.has.sprite || !node.has.name || !node.has.x || !node.has.y) continue;
|
||||
|
||||
var spr = XMLUtil.createSpriteFromXML(node, spritesParentFolder);
|
||||
|
||||
if (!node.has.zoomfactor && PlayState.instance != null)
|
||||
spr.initialZoom = PlayState.instance.defaultCamZoom;
|
||||
|
||||
stageSprites.set(spr.name, spr);
|
||||
state.add(spr);
|
||||
|
||||
@@ -460,15 +460,21 @@ class ShaderTemplates {
|
||||
}
|
||||
|
||||
uniform vec4 _camSize;
|
||||
|
||||
|
||||
float map(float value, float min1, float max1, float min2, float max2) {
|
||||
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
|
||||
}
|
||||
|
||||
vec2 getCamPos(vec2 pos) {
|
||||
return (pos * openfl_TextureSize / vec2(_camSize.z, _camSize.w)) + vec2(_camSize.x / _camSize.z, _camSize.y / _camSize.z);
|
||||
vec4 size = _camSize / vec4(openfl_TextureSize, openfl_TextureSize);
|
||||
return vec2(map(pos.x, size.x, size.x + size.z, 0.0, 1.0), map(pos.y, size.y, size.y + size.w, 0.0, 1.0));
|
||||
}
|
||||
vec2 camToOg(vec2 pos) {
|
||||
return ((pos - vec2(_camSize.x / _camSize.z, _camSize.y / _camSize.z)) * vec2(_camSize.z, _camSize.w) / openfl_TextureSize);
|
||||
vec4 size = _camSize / vec4(openfl_TextureSize, openfl_TextureSize);
|
||||
return vec2(map(pos.x, 0.0, 1.0, size.x, size.x + size.z), map(pos.y, 0.0, 1.0, size.y, size.y + size.w));
|
||||
}
|
||||
vec4 textureCam(sampler2D bitmap, vec2 pos) {
|
||||
return texture2D(bitmap, camToOg(pos));
|
||||
return flixel_texture2D(bitmap, camToOg(pos));
|
||||
}";
|
||||
|
||||
public static final fragBody:String = "vec4 color = texture2D (bitmap, openfl_TextureCoordv);
|
||||
|
||||
@@ -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