mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2024-12-18 12:02:33 -05:00
102 lines
2.7 KiB
Haxe
102 lines
2.7 KiB
Haxe
package funkin;
|
|
|
|
import flixel.FlxCamera;
|
|
import flixel.FlxSprite;
|
|
import flixel.math.FlxPoint;
|
|
|
|
class SwagCamera extends FlxCamera
|
|
{
|
|
/**
|
|
* properly follow framerate
|
|
* most of this just copied from FlxCamera,
|
|
* only lines 96 and 97 are changed
|
|
*/
|
|
override public function updateFollow():Void
|
|
{
|
|
// Either follow the object closely,
|
|
// or double check our deadzone and update accordingly.
|
|
if (deadzone == null)
|
|
{
|
|
target.getMidpoint(_point);
|
|
_point.addPoint(targetOffset);
|
|
focusOn(_point);
|
|
}
|
|
else
|
|
{
|
|
var edge:Float;
|
|
var targetX:Float = target.x + targetOffset.x;
|
|
var targetY:Float = target.y + targetOffset.y;
|
|
|
|
if (style == SCREEN_BY_SCREEN)
|
|
{
|
|
if (targetX >= (scroll.x + width))
|
|
{
|
|
_scrollTarget.x += width;
|
|
}
|
|
else if (targetX < scroll.x)
|
|
{
|
|
_scrollTarget.x -= width;
|
|
}
|
|
|
|
if (targetY >= (scroll.y + height))
|
|
{
|
|
_scrollTarget.y += height;
|
|
}
|
|
else if (targetY < scroll.y)
|
|
{
|
|
_scrollTarget.y -= height;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
edge = targetX - deadzone.x;
|
|
if (_scrollTarget.x > edge)
|
|
{
|
|
_scrollTarget.x = edge;
|
|
}
|
|
edge = targetX + target.width - deadzone.x - deadzone.width;
|
|
if (_scrollTarget.x < edge)
|
|
{
|
|
_scrollTarget.x = edge;
|
|
}
|
|
|
|
edge = targetY - deadzone.y;
|
|
if (_scrollTarget.y > edge)
|
|
{
|
|
_scrollTarget.y = edge;
|
|
}
|
|
edge = targetY + target.height - deadzone.y - deadzone.height;
|
|
if (_scrollTarget.y < edge)
|
|
{
|
|
_scrollTarget.y = edge;
|
|
}
|
|
}
|
|
|
|
if ((target is FlxSprite))
|
|
{
|
|
if (_lastTargetPosition == null)
|
|
{
|
|
_lastTargetPosition = FlxPoint.get(target.x, target.y); // Creates this point.
|
|
}
|
|
_scrollTarget.x += (target.x - _lastTargetPosition.x) * followLead.x;
|
|
_scrollTarget.y += (target.y - _lastTargetPosition.y) * followLead.y;
|
|
|
|
_lastTargetPosition.x = target.x;
|
|
_lastTargetPosition.y = target.y;
|
|
}
|
|
|
|
if (followLerp >= 60 / FlxG.updateFramerate)
|
|
{
|
|
scroll.copyFrom(_scrollTarget); // no easing
|
|
}
|
|
else
|
|
{
|
|
// THIS THE PART THAT ACTUALLY MATTERS LOL
|
|
scroll.x = CoolUtil.coolLerp(scroll.x, _scrollTarget.x, followLerp);
|
|
scroll.y = CoolUtil.coolLerp(scroll.y, _scrollTarget.y, followLerp);
|
|
// scroll.x += (_scrollTarget.x - scroll.x) * CoolUtil.camLerpShit(followLerp);
|
|
// scroll.y += (_scrollTarget.y - scroll.y) * CoolUtil.camLerpShit(followLerp);
|
|
}
|
|
}
|
|
}
|
|
}
|