Created
March 6, 2025 10:49
-
-
Save dogboydog/6a2e237c0ed6996cf92720ac01c72d54 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class GameplayCamera : Camera2D { | |
// dialogueRunner.AddCommandHandlerd("teleport_camera", TeleportCamera); | |
// dialogueRunner.AddCommandHandler("release_camera", ReleaseCamera); | |
// dialogueRunner.AddCommandHandler("start_camera_tween", | |
StartCameraTween); | |
private bool _scripted = false; | |
public void TeleportCamera(string markName) { | |
KillTweenIfActive(); | |
var mark = CameraMarkLookup.Find(markName); | |
if (!IsInstanceValid(mark)) { | |
Log.Err($"No camera mark called {markName} exists"); | |
return; | |
} | |
_scripted = true; | |
Instance.Position = mark.GlobalPosition; | |
} | |
/// <summary> | |
/// Gradually move the camera toward the specified CameraMark. | |
/// </summary> | |
/// <param name="markName">Which CameraMark to tween towards</param> | |
/// <param name="duration">How long the tween should take</param> | |
public void StartCameraTween(string markName, float duration) { | |
KillTweenIfActive(); | |
var mark = CameraMarkLookup.Find(markName); | |
if (!IsInstanceValid(mark)) { | |
Log.Err($"No camera mark called {markName} exists"); | |
return; | |
} | |
_scripted = true; | |
_tween = CreateTween(); | |
_tween.BindNode(this); | |
_tween.TweenProperty(this, "global_position", mark.GlobalPosition, duration); | |
} | |
/// <summary> | |
/// Make the camera follow the player again, no longer controlled by scripting. | |
/// </summary> | |
public void ReleaseCamera() { | |
KillTweenIfActive(); | |
_scripted = false; | |
} | |
public override void _PhysicsProcess(double deltaTime) { | |
if (!_initialized || _scripted) { | |
return; | |
} | |
// auto adjust camera based on input / follow player | |
} | |
private void KillTweenIfActive() { | |
if (_tween == null) { | |
return; | |
} | |
if (!IsInstanceValid(_tween)) { | |
_tween = null; | |
return; | |
} | |
_tween.Kill(); | |
_tween = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment