Godot下载:Download for Windows - Godot Engine
素材链接:https://jeanmakesgames.itch.io/2d-rpg-asset
Godot笔记:https://godot.ink
场景树
main_level是Node2D
Player是CharacterBody2D
Anim是AnimationPlayer
Player添加GDscript脚本
extends CharacterBody2D
#在GDScript中定义变量时,首先写下关键字var(variable的缩写),后面是变量名称,等号后面是它的初始值。
#var speed:int = 5 定义变量为整数类型,除此之外还有,float,string类型
#
#Vector2.ZERO零向量,所有分量都设置为 0 的向量。
var input_movement = Vector2.ZERO
var speed = 70
func _physics_process(delta):
move()
func move():
input_movement = Input.get_vector("ui_left","ui_right","ui_up","ui_down")
if input_movement != Vector2.ZERO :
velocity = input_movement * speed
if input_movement == Vector2.ZERO :
velocity = Vector2.ZERO
move_and_slide()
按住Ctrl键,然后移动鼠标,你会发现脚本编辑器中很多东西下方就会出现一条下划线:
变成小手的时候点一下,此时就来到了文档中对应的部分。
按下图目录结构保存
项目目录
Sprite2D添加精灵图,拖动Player-rpg到Texture,设置行列帧12,9
Camera2D设置区域 Zoom 3,3
CollisionShape2D设置碰撞体
如果图像模糊,可以在项目设置中->渲染->纹理->画布纹理,默认纹理过滤 Nearest