|
|
|
|
Reply From: |
Bojidar Marinov |
One idea would be to make a variable called time_left
, and decrement it in _fixed_process
by delta
. After it is less than zero, call the function you want.
Another way would be to use a Timer
node, and its timeout
signal:
timer.connect("timeout", self, "queue_free")
timer.set_wait_time(1)
timer.start()
A third way would be to use the Tween
node, which has some quite versatile uses…
tween.interpolate_callback(self, 1, "queue_free")
tween.start()
Ok, at the moment I use a custom timer in a the _process() method.
But because it’s a bit long to write, I also thought about a manager like this:
some_global_script.execute_later(self, "my_callback", 2)
Zylann | 2016-03-19 13:39
Well, you can easily set this up with the Tween approach.
Bojidar Marinov | 2016-03-19 14:44
Yes, but it involves the creation of a node anyways.
Zylann | 2016-03-19 18:42
Since global (autoload) scripts are also nodes, it wouldn’t be a big deal to add_child(my_new_shiny_subnode)… except that you would have to refer to them by variable, and not by name.
Bojidar Marinov | 2016-03-19 18:47
It’s just a matter of saving a node, in case I’m going to have many instances of the scene requesting the invoke_later(). But at the moment I don’t care that much, so I’ll take the option requiring the less work
Zylann | 2016-03-19 18:54