fixed zoomfactor
Co-Authored-By: Ne_Eo <NeeEoo@users.noreply.github.com>
This commit is contained in:
@@ -39,9 +39,11 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
public var beatAnims:Array<BeatAnim> = [];
|
||||
public var name:String;
|
||||
public var zoomFactor:Float = 1;
|
||||
public var initialZoom:Float = 1;
|
||||
//public var initialZoom:Float = 1;
|
||||
public var debugMode:Bool = false;
|
||||
public var animDatas:Map<String, AnimData> = [];
|
||||
public var animEnabled:Bool = true;
|
||||
public var zoomFactorEnabled:Bool = true;
|
||||
|
||||
/**
|
||||
* ODD interval -> asynced; EVEN interval -> synced
|
||||
@@ -87,7 +89,6 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
spr.transformMatrix = source.transformMatrix;
|
||||
spr.matrixExposed = source.matrixExposed;
|
||||
spr.zoomFactor = source.zoomFactor;
|
||||
spr.initialZoom = source.initialZoom;
|
||||
spr.animOffsets = source.animOffsets.copy();
|
||||
}
|
||||
return spr;
|
||||
@@ -140,49 +141,6 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
{
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
__oldScrollFactor.set(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(__oldScrollFactor.x, __oldScrollFactor.y);
|
||||
|
||||
return r;
|
||||
}
|
||||
return super.getScreenPosition(point, Camera);
|
||||
}
|
||||
|
||||
// ANIMATE ATLAS DRAWING
|
||||
#if REGION
|
||||
public override function draw()
|
||||
@@ -238,33 +196,51 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
}
|
||||
#end
|
||||
|
||||
// SCALING FUNCS
|
||||
#if REGION
|
||||
private inline function __shouldDoScaleProcedure()
|
||||
return zoomFactor != 1;
|
||||
// ZOOM FACTOR
|
||||
private inline function __shouldDoZoomFactor()
|
||||
return zoomFactorEnabled && zoomFactor != 1;
|
||||
|
||||
static var __oldScrollFactor:FlxPoint = new FlxPoint();
|
||||
static var __oldScale:FlxPoint = new FlxPoint();
|
||||
var __skipZoomProcedure:Bool = false;
|
||||
|
||||
private function __doPreZoomScaleProcedure(camera:FlxCamera)
|
||||
public override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect
|
||||
{
|
||||
if (__skipZoomProcedure = !__shouldDoScaleProcedure())
|
||||
return;
|
||||
__oldScale.set(scale.x, scale.y);
|
||||
var requestedZoom = FlxMath.lerp(initialZoom, camera.zoom, zoomFactor);
|
||||
var diff = requestedZoom * camera.zoom;
|
||||
if (camera == null)
|
||||
camera = FlxG.camera;
|
||||
|
||||
scale.scale(diff);
|
||||
var r = super.getScreenBounds(newRect, camera);
|
||||
|
||||
if(__shouldDoZoomFactor()) {
|
||||
r.x -= camera.width / 2;
|
||||
r.y -= camera.height / 2;
|
||||
|
||||
var ratio = FlxMath.lerp(1 / camera.zoom, 1, zoomFactor);
|
||||
r.x *= ratio;
|
||||
r.y *= ratio;
|
||||
|
||||
r.width *= ratio;
|
||||
r.height *= ratio;
|
||||
|
||||
r.x += camera.width / 2;
|
||||
r.y += camera.height / 2;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private function __doPostZoomScaleProcedure()
|
||||
public override function doAdditionalMatrixStuff(matrix:FlxMatrix, camera:FlxCamera)
|
||||
{
|
||||
if (__skipZoomProcedure)
|
||||
return;
|
||||
scale.set(__oldScale.x, __oldScale.y);
|
||||
super.doAdditionalMatrixStuff(matrix, camera);
|
||||
if(__shouldDoZoomFactor()) {
|
||||
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
|
||||
{
|
||||
return super.getScreenPosition(point, Camera);
|
||||
}
|
||||
#end
|
||||
|
||||
// OFFSETTING
|
||||
#if REGION
|
||||
@@ -352,6 +328,11 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
public inline function isAnimFinished() {
|
||||
return animateAtlas != null ? (animateAtlas.anim.finished) : (animation.curAnim != null ? animation.curAnim.finished : true);
|
||||
}
|
||||
|
||||
override function updateAnimation(elapsed:Float) {
|
||||
if (animEnabled)
|
||||
super.updateAnimation(elapsed);
|
||||
}
|
||||
#end
|
||||
|
||||
// Getter / Setters
|
||||
|
||||
@@ -226,9 +226,20 @@ class StageEditor extends UIState {
|
||||
stage.onXMLLoaded = function(xml:Access, elems:Array<Access>) {
|
||||
return elems;
|
||||
}
|
||||
stage.onNodeLoadedPost = function(node:Access, sprite:Dynamic) {
|
||||
if(sprite is FlxSprite) {
|
||||
sprite.moves = false;
|
||||
}
|
||||
if (sprite is FunkinSprite) {
|
||||
sprite.animEnabled = false;
|
||||
//sprite.zoomFactorEnabled = false;
|
||||
}
|
||||
}
|
||||
stage.onNodeLoaded = function(node:Access, sprite:Dynamic):Dynamic {
|
||||
if(sprite is FlxSprite) {
|
||||
//sprite.forceIsOnScreen = true; // hack
|
||||
}
|
||||
if(sprite is FunkinSprite) {
|
||||
sprite.forceIsOnScreen = true; // hack
|
||||
sprite.extra.set(exID("type"), node.name);
|
||||
//sprite.active = false;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ class SplashGroup extends FlxTypedGroup<FunkinSprite> {
|
||||
|
||||
// immediatly draw once and put image in GPU to prevent freezes
|
||||
// TODO: change to graphics cache
|
||||
@:privateAccess
|
||||
splash.drawComplex(FlxG.camera);
|
||||
} catch(e:Dynamic) {
|
||||
Logs.trace('Couldn\'t parse splash data for "${path}": ${e.toString()}', ERROR);
|
||||
|
||||
@@ -29,6 +29,7 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
||||
|
||||
public var onXMLLoaded:(Access, Array<Access>)->Array<Access> = null;
|
||||
public var onNodeLoaded:(Access, Dynamic)->Dynamic = null;
|
||||
public var onNodeLoadedPost:(Access, Dynamic)->Void = null;
|
||||
|
||||
private var spritesParentFolder = "";
|
||||
|
||||
@@ -109,9 +110,6 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
||||
|
||||
var spr = XMLUtil.createSpriteFromXML(node, spritesParentFolder, LOOP);
|
||||
|
||||
if (!node.has.zoomfactor/* && PlayState.instance == state*/)
|
||||
spr.initialZoom = defaultZoom;//PlayState.instance.defaultCamZoom;
|
||||
|
||||
stageSprites.set(spr.name, spr);
|
||||
state.add(spr);
|
||||
spr;
|
||||
@@ -130,9 +128,6 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
||||
(node.has.color) ? CoolUtil.getColorFromDynamic(node.att.color) : -1
|
||||
);
|
||||
|
||||
if (!node.has.zoomfactor/* && PlayState.instance == state*/)
|
||||
spr.initialZoom = defaultZoom;//PlayState.instance.defaultCamZoom;
|
||||
|
||||
stageSprites.set(spr.name, spr);
|
||||
state.add(spr);
|
||||
spr;
|
||||
@@ -182,6 +177,10 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
||||
for(e in node.nodes.property)
|
||||
XMLUtil.applyXMLProperty(sprite, e);
|
||||
}
|
||||
|
||||
if(onNodeLoadedPost != null) {
|
||||
onNodeLoadedPost(node, sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user