diff options
Diffstat (limited to 'demos/misc/threads')
-rw-r--r-- | demos/misc/threads/engine.cfg | 4 | ||||
-rw-r--r-- | demos/misc/threads/mona.png | bin | 0 -> 98894 bytes | |||
-rw-r--r-- | demos/misc/threads/thread.gd | 31 | ||||
-rw-r--r-- | demos/misc/threads/thread.scn | bin | 0 -> 1638 bytes |
4 files changed, 35 insertions, 0 deletions
diff --git a/demos/misc/threads/engine.cfg b/demos/misc/threads/engine.cfg new file mode 100644 index 0000000000..6f19936c9d --- /dev/null +++ b/demos/misc/threads/engine.cfg @@ -0,0 +1,4 @@ +[application] + +name="Loading in a Thread" +main_scene="res://thread.scn" diff --git a/demos/misc/threads/mona.png b/demos/misc/threads/mona.png Binary files differnew file mode 100644 index 0000000000..0bcda570b4 --- /dev/null +++ b/demos/misc/threads/mona.png diff --git a/demos/misc/threads/thread.gd b/demos/misc/threads/thread.gd new file mode 100644 index 0000000000..7d8aabd1b7 --- /dev/null +++ b/demos/misc/threads/thread.gd @@ -0,0 +1,31 @@ + +extends Node2D + +# member variables here, example: +# var a=2 +# var b="textvar" + +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") diff --git a/demos/misc/threads/thread.scn b/demos/misc/threads/thread.scn Binary files differnew file mode 100644 index 0000000000..349127529a --- /dev/null +++ b/demos/misc/threads/thread.scn |