Godot Engine:如何在_input(event)方法中判断某个输入事件“刚刚”发生

func _input(event)中传入的参数event是一个InputEvent类型,这个类型没有直接判断“刚刚”发生的方法,所以要如下判断:

 	e.is_action_pressed(action) and not e.is_echo()

可以把这段代码写成一个静态的帮助类

#InputHelper.gd
class_name InputHelper

static func is_action_pressed(e :InputEvent,action:String):
	return e.is_action_pressed(action)

static func is_action_just_pressed(e :InputEvent,action:String):
	return e.is_action_pressed(action) and not e.is_echo()

这样我们使用的时候只要:

func _input(event):
	if  InputHelper.is_action_just_pressed(event):
		...
		pass
发布了394 篇原创文章 · 获赞 1508 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/hello_tute/article/details/105328460
今日推荐