代码拉取完成,页面将自动刷新
using Godot;
using System.Linq;
public partial class Global : Node2D
{
public static Global Instance { get; private set; }
public Camera2D Camera;
///<summary>从摄像机当前视图所对应戳到的场景的坐标。</summary>
public Vector2 GlobalMousePosition;
public Node MainNode;
public Icon Player;
public override void _Ready()
{
Instance = this;
base._Ready();
var root = GetParent();
var main = root.GetChildren().Last();
if (main.HasNode("Camera2D") == false)
{
Camera = new Camera2D()
{
AnchorMode = Camera2D.AnchorModeEnum.FixedTopLeft,
};
AddChild(Camera);
}
else
{
Camera = main.GetNode<Camera2D>("Camera2D");
Camera.AnchorMode = Camera2D.AnchorModeEnum.FixedTopLeft;
}
Player = main.GetChildren().OfType<Icon>().FirstOrDefault();
MainNode = main;
}
public override void _Process(double delta)
{
var globalMousePosition = GetGlobalMousePosition();
GlobalMousePosition = globalMousePosition;
//GD.Print(globalMousePosition);
//var mousePos = GetViewport().GetMousePosition();
//GD.Print(mousePos);
//var viewportRect = GetViewportRect();
//var smallRect = viewportRect.Grow(-200);
HandleMovement();
base._Process(delta);
}
private void HandleMovement()
{
if (Input.IsActionJustPressed("ui_left"))
{
var leftPos = Vector2.Left * 200;
var tween = GetTree().CreateTween();
tween.TweenProperty(Camera, "offset", Camera.Offset + leftPos, 1)
.SetEase(Tween.EaseType.Out)
.SetTrans(Tween.TransitionType.Quint);
//Camera.Offset = Camera.Offset + leftPos;
}
if (Input.IsActionJustPressed("ui_up"))
{
var leftPos = Vector2.Up * 200;
var tween = GetTree().CreateTween();
tween.TweenProperty(Camera, "offset", Camera.Offset + leftPos, 1)
.SetEase(Tween.EaseType.Out)
.SetTrans(Tween.TransitionType.Quint);
//Camera.Offset = Camera.Offset + leftPos;
}
if (Input.IsActionJustPressed("ui_down"))
{
var leftPos = Vector2.Down * 200;
var tween = GetTree().CreateTween();
tween.TweenProperty(Camera, "offset", Camera.Offset + leftPos, 1)
.SetEase(Tween.EaseType.Out)
.SetTrans(Tween.TransitionType.Quint);
//Camera.Offset = Camera.Offset + leftPos;
}
if (Input.IsActionJustPressed("ui_right"))
{
var leftPos = Vector2.Right * 200;
var tween = GetTree().CreateTween();
tween.TweenProperty(Camera, "offset", Camera.Offset + leftPos, 1)
.SetEase(Tween.EaseType.Out)
.SetTrans(Tween.TransitionType.Quint);
//Camera.Offset = Camera.Offset + leftPos;
}
}
public override void _EnterTree()
{
base._EnterTree();
}
public override void _ExitTree()
{
base._ExitTree();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。