窗口控制:
高级选项
k384
g216
覆盖1152
g648
拉伸 canvas items
主要地图world
1.node2d
2.tilemap :新建tileset 点一下,然后再点physics Layers的添加元素,然后再tileset拖入图片,设置,然后绘制加刚体,只有在tile map才可以画上去
3.后来player导入就行
子控件 玩家部分
1.characterBody2.0 改名为player就是一个文件夹
2.sprite2d 用来存放人物素材
3.collisionShape2D 刚体,用来和地面接触
4.AnimationPlay 和2配合使用,用来动画,主要就是记得加3个和第一帧。
5.代码在文件夹1创立,然后就是先绑定按键,项目映射输入,3个,然后就是复制了,代码主要是一些调用和判断的作用。
extends CharacterBody2D
const Runspeed :=200.0
const JUNPvelocuty :=-300.0
var gravity := ProjectSettings.get("physics/2d/default_gravity") as float
@onready var sprite_2d:Sprite2D = $Sprite2D
@onready var animation_player: AnimationPlayer = $AnimationPlayer
func _physics_process(delte: float) -> void:
var direction :=Input.get_axis("move_left","move_right")
velocity.x = direction * Runspeed
velocity.y += gravity*delte
if is_on_floor() and Input.is_action_just_pressed("jump"):
velocity.y = JUNPvelocuty
if is_on_floor():
if is_zero_approx(direction):
animation_player.play("idle")
else:
animation_player.play("running")
else:
animation_player.play("jump")
if not is_zero_approx(direction):
sprite_2d.flip_h = direction < 0
move_and_slide()