您当前的位置: 首页 > 

开发游戏的老王

暂无认证

  • 2浏览

    0关注

    803博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

开发游戏的老王 发布时间:2020-04-05 16:16:05 ,浏览量:2

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
关注
打赏
1656935939
查看更多评论
立即登录/注册

微信扫码登录

0.0412s