From 0b806ee0fc9097fa7bda7ac0109191c9c5e0a1ac Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 9 Feb 2014 22:10:30 -0300 Subject: GODOT IS OPEN SOURCE --- demos/misc/autoload/engine.cfg | 8 ++++++++ demos/misc/autoload/global.gd | 23 +++++++++++++++++++++++ demos/misc/autoload/scene_a.gd | 17 +++++++++++++++++ demos/misc/autoload/scene_a.scn | Bin 0 -> 1459 bytes demos/misc/autoload/scene_b.gd | 17 +++++++++++++++++ demos/misc/autoload/scene_b.scn | Bin 0 -> 1448 bytes demos/misc/pause/engine.cfg | 5 +++++ demos/misc/pause/icon.png | Bin 0 -> 5236 bytes demos/misc/pause/spinpause.gd | 15 +++++++++++++++ demos/misc/pause/spinpause.scn | Bin 0 -> 3331 bytes demos/misc/threads/engine.cfg | 4 ++++ demos/misc/threads/mona.png | Bin 0 -> 98894 bytes demos/misc/threads/thread.gd | 31 +++++++++++++++++++++++++++++++ demos/misc/threads/thread.scn | Bin 0 -> 1638 bytes 14 files changed, 120 insertions(+) create mode 100644 demos/misc/autoload/engine.cfg create mode 100644 demos/misc/autoload/global.gd create mode 100644 demos/misc/autoload/scene_a.gd create mode 100644 demos/misc/autoload/scene_a.scn create mode 100644 demos/misc/autoload/scene_b.gd create mode 100644 demos/misc/autoload/scene_b.scn create mode 100644 demos/misc/pause/engine.cfg create mode 100644 demos/misc/pause/icon.png create mode 100644 demos/misc/pause/spinpause.gd create mode 100644 demos/misc/pause/spinpause.scn create mode 100644 demos/misc/threads/engine.cfg create mode 100644 demos/misc/threads/mona.png create mode 100644 demos/misc/threads/thread.gd create mode 100644 demos/misc/threads/thread.scn (limited to 'demos/misc') diff --git a/demos/misc/autoload/engine.cfg b/demos/misc/autoload/engine.cfg new file mode 100644 index 0000000000..c6ad023013 --- /dev/null +++ b/demos/misc/autoload/engine.cfg @@ -0,0 +1,8 @@ +[application] + +name="Autoload (Singletons)" +main_scene="res://scene_a.scn" + +[autoload] + +global="res://global.gd" diff --git a/demos/misc/autoload/global.gd b/demos/misc/autoload/global.gd new file mode 100644 index 0000000000..d9fa308a2f --- /dev/null +++ b/demos/misc/autoload/global.gd @@ -0,0 +1,23 @@ +extends Node + + +var current_scene = null + + +func goto_scene(scene): + #load new scene + var s = ResourceLoader.load(scene) + #queue erasing old (don't use free because that scene is calling this method) + current_scene.queue_free() + #instance the new scene + current_scene = s.instance() + #add it to the active scene, as child of root + get_scene().get_root().add_child(current_scene) + + +func _ready(): + # get the current scene + # it is always the last child of root, + # after the autoloaded nodes + var root = get_scene().get_root() + current_scene = root.get_child( root.get_child_count() -1 ) diff --git a/demos/misc/autoload/scene_a.gd b/demos/misc/autoload/scene_a.gd new file mode 100644 index 0000000000..21a6a84eb9 --- /dev/null +++ b/demos/misc/autoload/scene_a.gd @@ -0,0 +1,17 @@ + +extends Panel + +# member variables here, example: +# var a=2 +# var b="textvar" + +func _ready(): + # Initalization here + pass + + + + +func _on_goto_scene_pressed(): + get_node("/root/global").goto_scene("res://scene_b.scn") + pass # replace with function body diff --git a/demos/misc/autoload/scene_a.scn b/demos/misc/autoload/scene_a.scn new file mode 100644 index 0000000000..61727a57ba Binary files /dev/null and b/demos/misc/autoload/scene_a.scn differ diff --git a/demos/misc/autoload/scene_b.gd b/demos/misc/autoload/scene_b.gd new file mode 100644 index 0000000000..4a88fddda9 --- /dev/null +++ b/demos/misc/autoload/scene_b.gd @@ -0,0 +1,17 @@ + +extends Panel + +# member variables here, example: +# var a=2 +# var b="textvar" + +func _ready(): + # Initalization here + pass + + + + +func _on_goto_scene_pressed(): + get_node("/root/global").goto_scene("res://scene_a.scn") + pass # replace with function body diff --git a/demos/misc/autoload/scene_b.scn b/demos/misc/autoload/scene_b.scn new file mode 100644 index 0000000000..ae09eeff88 Binary files /dev/null and b/demos/misc/autoload/scene_b.scn differ diff --git a/demos/misc/pause/engine.cfg b/demos/misc/pause/engine.cfg new file mode 100644 index 0000000000..a5cb20cc7f --- /dev/null +++ b/demos/misc/pause/engine.cfg @@ -0,0 +1,5 @@ +[application] + +name="Pause" +main_scene="res://spinpause.scn" +icon="res://icon.png" diff --git a/demos/misc/pause/icon.png b/demos/misc/pause/icon.png new file mode 100644 index 0000000000..49b3fd4053 Binary files /dev/null and b/demos/misc/pause/icon.png differ diff --git a/demos/misc/pause/spinpause.gd b/demos/misc/pause/spinpause.gd new file mode 100644 index 0000000000..c21c13b4e1 --- /dev/null +++ b/demos/misc/pause/spinpause.gd @@ -0,0 +1,15 @@ + +extends Spatial + + +func _on_pause_pressed(): + get_node("pause_popup").set_exclusive(true) + get_node("pause_popup").popup() + get_scene().set_pause(true) + + +func _on_unpause_pressed(): + get_node("pause_popup").hide() + get_scene().set_pause(false) + + diff --git a/demos/misc/pause/spinpause.scn b/demos/misc/pause/spinpause.scn new file mode 100644 index 0000000000..a3835c4374 Binary files /dev/null and b/demos/misc/pause/spinpause.scn differ 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 new file mode 100644 index 0000000000..0bcda570b4 Binary files /dev/null and b/demos/misc/threads/mona.png differ 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 new file mode 100644 index 0000000000..349127529a Binary files /dev/null and b/demos/misc/threads/thread.scn differ -- cgit v1.2.3