2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
extends Node2D
|
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Member variables
|
2014-02-10 01:10:30 +00:00
|
|
|
var thread = Thread.new()
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# This function runs in a thread!
|
|
|
|
# Threads always take one userdata argument
|
2014-02-10 01:10:30 +00:00
|
|
|
func _bg_load(path):
|
|
|
|
print("THREAD FUNC!")
|
2015-11-21 12:31:25 +00:00
|
|
|
# Load the resource
|
2014-02-10 01:10:30 +00:00
|
|
|
var tex = ResourceLoader.load(path)
|
2015-11-21 12:31:25 +00:00
|
|
|
# Call _bg_load_done on main thread
|
2014-02-10 01:10:30 +00:00
|
|
|
call_deferred("_bg_load_done")
|
2015-12-09 07:38:23 +00:00
|
|
|
return tex # return it
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
func _bg_load_done():
|
2015-11-21 12:31:25 +00:00
|
|
|
# Wait for the thread to complete, get the returned value
|
2014-02-10 01:10:30 +00:00
|
|
|
var tex = thread.wait_to_finish()
|
2015-11-21 12:31:25 +00:00
|
|
|
# Set to the sprite
|
2014-02-10 01:10:30 +00:00
|
|
|
get_node("sprite").set_texture(tex)
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
func _on_load_pressed():
|
|
|
|
if (thread.is_active()):
|
2015-11-21 12:31:25 +00:00
|
|
|
# Already working
|
2014-02-10 01:10:30 +00:00
|
|
|
return
|
|
|
|
print("START THREAD!")
|
2015-12-09 07:38:23 +00:00
|
|
|
thread.start(self, "_bg_load", "res://mona.png")
|