add 注释

This commit is contained in:
Weihao.L 2024-09-12 23:00:26 +08:00
parent 29decd4384
commit 6622e33f35
2 changed files with 9 additions and 0 deletions

View File

@ -0,0 +1 @@
2ddemo

View File

@ -22,30 +22,38 @@ public partial class Player : Area2D
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
// Player坐标 初始化00
var velocity = Vector2.Zero; // The player's movement vector.
// 如果按下右键 X轴+1
if (Input.IsActionPressed("move_right"))
{
velocity.X += 1;
}
// 左键 X轴-1
if (Input.IsActionPressed("move_left"))
{
velocity.X -= 1;
}
// 下键 Y轴+1
if (Input.IsActionPressed("move_down"))
{
velocity.Y += 1;
}
// 上键 Y轴-1
if (Input.IsActionPressed("move_up"))
{
velocity.Y -= 1;
}
// 动画 获取AnimatedSprite2D节点
var animatedSprite2D = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
// 如果坐标的length大于0
if (velocity.Length() > 0)
{
velocity = velocity.Normalized() * Speed;