godot/demos/misc/threads/thread.gd
Rémi Verschelde 8639cecf4c Improve code formatting and update to 2.0
The scripts were streamlined using more or less the following conventions:
 - space after a comma in lists of arguments
 - space around weak operators (+, -), no space around strong operators (*, /)
 - space after a comment start (#)
 - removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now)
 - function blocks separate by two newlines

The scene files were resaved with the (current) 2.0 format, and some scenes that were in XML format were converted to SCN, to be consistent across all demos.
2015-12-09 08:38:23 +01:00

32 lines
670 B
GDScript

extends Node2D
# member variables
var thread = Thread.new()
# this function runs in a thread!
# threads always take one userdata argument
func _bg_load(path):
print("THREAD FUNC!")
# load the resource
var tex = ResourceLoader.load(path)
# call _bg_load_done on main thread
call_deferred("_bg_load_done")
return tex # return it
func _bg_load_done():
# wait for the thread to complete, get the returned value
var tex = thread.wait_to_finish()
# set to the sprite
get_node("sprite").set_texture(tex)
func _on_load_pressed():
if (thread.is_active()):
# already working
return
print("START THREAD!")
thread.start(self, "_bg_load", "res://mona.png")