Godot 学习笔记(1):环境配置

文章目录

前言

我从小就有个梦想,我想做游戏。虽然我大学的时候选择了计算机,工作也是计算机,但是我一直没有时间去学游戏引擎。原因有二:第一,我刚开始工作并没有那么强的代码能力。第二,我工作并不是写游戏代码。

那么为什么我要选择Godot呢?原因如下

  • Godot.net有 C# 的代码支持
  • Godot.net 2d已经足够完善,而作为独立游戏开发,完全没必要去做3d游戏,因为2d游戏已经足够。
  • 不喜欢Unity。Godot 开源免费。

Godot 环境配置

我目前的环境是

  • godot.net 4.2.1
  • visual studio 2022
  • window 10
  • .net core 8.0

相关链接

Godot 初学
Godot VisualStudio外部编辑器设置
Godot 添加Nuget 引用
Godot 添加信号

注意,我这里默认你已经了解最简单的Godot 编辑器操作。并且完成了上面博客的功能。

最简单的按钮项目

这里新建两个控件,按钮控件和文本控件。

Sence打包


最简单的按钮事件

csharp 复制代码
using Godot;
using System;
using System.Diagnostics;

public partial class test_node : Node2D
{
    // Called when the node enters the scene tree for the first time.

    private Label _lable;

    private Button _button;

    private int num = 0;

    public override void _Ready()
    {
        _lable = this.GetNode<Label>("Label");

        _button = this.GetNode<Button>("Button");

        _lable.Text = "修改";

        _button.ButtonDown += _button_ButtonDown;
    }

    public void _button_ButtonDown()
    {
        _lable.Text = $"按下修改{num}";
        GD.Print($"按下修改{num}");
        num++;
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
    {
    }

}

总结

这里简单讲解了Godot的基础和简单的项目案例。我们后面大部分的功能都是基于button和lable来实现的。下一节我们将讲解最复杂的信号。

相关推荐
姜鱼问生1 小时前
Nginx 缓存命中率监控:从 X-Cache-Status 到实时统计
运维·nginx·缓存
代码什么用3 小时前
Spring基础使用
java·后端·spring
Su米苏3 小时前
Spring AI 中MCP 与普通 @Tool的区别
java·人工智能·spring
码云数智-园园3 小时前
unique_ptr 还是 shared_ptr?C++ 智能指针选型与内存泄漏实战分析
java·开发语言
老板一杯拿铁4 小时前
Java 异常体系详解:从字节码原理到最佳实践
java
蜗牛互联网4 小时前
Java 17 HttpClient调用文件转写API的超时与失败回退
java·人工智能·后端
禾小西4 小时前
07丨Redis 哨兵机制:主库故障后,如何恢复服务?
java·开发语言·redis
我不是阵雨4 小时前
JDK 21虚拟线程Pinning陷阱:一文拔钉解困
java·开发语言
小卡车5555 小时前
java反射、自定义注解的应用(自定义分页)
java
BLUcoding5 小时前
接口服务公网超时排查记录:SecureRandom 阻塞问题分析与解决
java·linux·springboot·aes·securerandom