1 Star 0 Fork 0

fanbal/TestGameGowalk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Global.cs 3.18 KB
一键复制 编辑 原始数据 按行查看 历史
fanbal 提交于 2024-07-22 00:02 . test2
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();
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fanbal/test-game-gowalk.git
git@gitee.com:fanbal/test-game-gowalk.git
fanbal
test-game-gowalk
TestGameGowalk
master

搜索帮助