您当前的位置: 首页 > 

开发游戏的老王

暂无认证

  • 2浏览

    0关注

    803博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

GDScript:如何Disable一个Node

开发游戏的老王 发布时间:2020-01-05 14:29:31 ,浏览量:2

在Godot中,"disable"一个Node的最简单办法就是把它从场景树中移除,但不删除它,这样当我们想启用它的时候可以再把它加入场景树,注意把节点从场景树移除的时候,同时也将它从所在组里移除了,如果我们想把它保留到组里,可能就要用到下面的方法。

Node类本身没有hideshow方法,所以调用前先用has_method判断一下:

class_name NodeHelper

static func disable(node:Node):
	if is_instance_valid(node):
		node.set_process(false)
		node.set_process_internal(false)
		node.set_physics_process(false)
		node.set_physics_process_internal(false)
		node.set_process_input(false)
		node.set_process_unhandled_input(false)
		node.set_process_unhandled_key_input(false)
		if node.has_method("hide"):
			node.hide()
	else:
		printerr("the node you are trying to disable is not valid")

static func enable(node:Node):
	if is_instance_valid(node):
		node.set_process(true)
		node.set_process_internal(true)
		node.set_physics_process(true)
		node.set_physics_process_internal(true)
		node.set_process_input(true)
		node.set_process_unhandled_input(true)
		node.set_process_unhandled_key_input(true)
		if node.has_method("show"):
			node.show()
	else:
		printerr("the node you are trying to enable is not valid")

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

微信扫码登录

0.0378s