您当前的位置: 首页 > 

开发游戏的老王

暂无认证

  • 2浏览

    0关注

    803博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Node类:用_input方法异步获取键盘输入

开发游戏的老王 发布时间:2019-10-20 19:45:33 ,浏览量:2

Godot Engine 3.2Alpha2

获取键盘按下事件

直接使用scancode

extends Node

func _ready()
	pass

func _input(e):
	if e is InputEventKey and e.pressed and not e.echo: 
	#筛选键盘输入事件 and 键盘按下事件 and 非一直按下状态
		match e.scancode:
			KEY_1:
				print("1")
			KEY_2:
				print("2")
			KEY_3:
				print("3")
			_:
				print("_")

使用预定义的InputMap

extends Node

func _ready()
	pass

func _input(e):
	if e is InputEventKey and e.pressed and not e.echo: 
	#下面使用e.is_action_pressed也是可以的,由于上面已经筛选了按下事件,所以可以直接用e.is_action
		if e.is_action("ui_up"):
			print("1")
		elif e.is_action("ui_down"):
			print("2")
		elif e.is_action("ui_left"):
			print("3")
		elif e.is_action("ui_right"):
			print("4")
		else:
			print("5")	

关注
打赏
1656935939
查看更多评论
立即登录/注册

微信扫码登录

0.0382s