mirror of
https://github.com/godotengine/godot.git
synced 2024-11-24 05:04:10 +00:00
oops
parent
04efbfed19
commit
6956f5e02c
@ -67,7 +67,7 @@ var time_max = 100 # msec
|
||||
var current_scene
|
||||
|
||||
func _ready():
|
||||
var root = get_scene().get_root()
|
||||
var root = get_tree().get_root()
|
||||
current_scene = root.get_child( root.get_child_count() -1 )
|
||||
```
|
||||
|
||||
|
@ -659,7 +659,7 @@ The real strength of using yield() is when combined with signals (if you haven't
|
||||
```python
|
||||
|
||||
#resume execution the next frame
|
||||
yield( get_scene(), "idle_frame" )
|
||||
yield( get_tree(), "idle_frame" )
|
||||
|
||||
#resume execution when animation is done playing:
|
||||
yield( get_node("AnimationPlayer"), "finished" )
|
||||
|
4
Home.md
4
Home.md
@ -6,7 +6,7 @@ Welcome to the Godot Engine documentation center. The aim of these pages is to p
|
||||
# Notice!
|
||||
|
||||
Some types and method names are about to change in the next days, please read this:
|
||||
* [SceneMainLoop - SceneTree Notes](devel_scene_tree)
|
||||
* [SceneTree - SceneTree Notes](devel_scene_tree)
|
||||
|
||||
# Roadmap
|
||||
|
||||
@ -29,7 +29,7 @@ Some types and method names are about to change in the next days, please read th
|
||||
9. [Animation](tutorial_animation)
|
||||
10. [Resources](tutorial_resources)
|
||||
11. [File System](tutorial_fs)
|
||||
12. [SceneMainLoop](tutorial_scene_main_loop)
|
||||
12. [SceneTree](tutorial_scene_main_loop)
|
||||
13. [Singletons (Autoload)](tutorial_singletons)
|
||||
|
||||
#### Engine
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
### Member Functions
|
||||
* [Object](class_object) **[get_scene](#get_scene)** **(** **)**
|
||||
* [Object](class_object) **[get_scene](#get_tree)** **(** **)**
|
||||
* [int](class_int) **[poll](#poll)** **(** **)**
|
||||
* [int](class_int) **[get_stage](#get_stage)** **(** **)** const
|
||||
* [int](class_int) **[get_stage_count](#get_stage_count)** **(** **)** const
|
||||
|
@ -80,14 +80,14 @@ user@host:~/newgame$ godot -export Android /var/builds/project.apk
|
||||
### Running a Script
|
||||
|
||||
It is possible to run a simple .gd script from the command line. This feature is specially useful in very large projects, for batch conversion of assets or custom import/export.
|
||||
The script must inherit from SceneMainLoop or MainLoop.
|
||||
The script must inherit from SceneTree or MainLoop.
|
||||
|
||||
Here is a simple example of how it works:
|
||||
|
||||
|
||||
```python
|
||||
#sayhello.gd
|
||||
extends SceneMainLoop
|
||||
extends SceneTree
|
||||
|
||||
func _init():
|
||||
print("Hello!")
|
||||
|
@ -9,7 +9,7 @@ c:\godot> godot -s http_test.gd
|
||||
It will connect and fetch a website.
|
||||
|
||||
```python
|
||||
extends SceneMainLoop
|
||||
extends SceneTree
|
||||
|
||||
# HTTPClient demo
|
||||
# This simple class can do HTTP requests, it will not block but it needs to be polled
|
||||
|
2
start.md
2
start.md
@ -17,7 +17,7 @@ Welcome to the Godot Engine documentation center. The aim of these pages is to p
|
||||
7. [Animation](tutorial_animation)
|
||||
8. [Resources](tutorial_resources)
|
||||
9. [File System](tutorial_fs)
|
||||
10. [SceneMainLoop](tutorial_scene_main_loop)
|
||||
10. [SceneTree](tutorial_scene_main_loop)
|
||||
11. [Singletons (Autoload)](tutorial_singletons)
|
||||
|
||||
#### Intermediate
|
||||
|
@ -10,7 +10,7 @@ However, what it does is not completely obvious. When running on PC, the engine
|
||||
|
||||
### Resizing
|
||||
|
||||
There are several types of devices, with several types of screens, which in turn have different pixel density and resolutions. Handling all of them can be a lot of work, so Godot tries to make the developer's life a little easier. The [Viewport](class_viewport) node has several functions to handle resizing, and the root node of the scene tree is always a viewport (scenes loaded are instanced as a child of it, and it can always be accessed by calling `get_scene().get_root()` or `get_node("/root")` ).
|
||||
There are several types of devices, with several types of screens, which in turn have different pixel density and resolutions. Handling all of them can be a lot of work, so Godot tries to make the developer's life a little easier. The [Viewport](class_viewport) node has several functions to handle resizing, and the root node of the scene tree is always a viewport (scenes loaded are instanced as a child of it, and it can always be accessed by calling `get_tree().get_root()` or `get_node("/root")` ).
|
||||
|
||||
In any case, while changing the root Viewport params is probably the most flexible way to deal with the problem, it can be a lot of work, code and guessing, so Godot provides a simple set of parameters in the project settings to handle multiple resolutions.
|
||||
|
||||
|
@ -13,7 +13,7 @@ Handling it is done as follows (on any node):
|
||||
```python
|
||||
func _notification(what):
|
||||
if (what==MainLoop.NOTIFICATION_WM_QUIT_REQUEST):
|
||||
get_scene().quit() #default behavior
|
||||
get_tree().quit() #default behavior
|
||||
```
|
||||
|
||||
When developing mobile apps, quitting is not desired unless the user is on the main screen, so the behavior can be changed.
|
||||
@ -21,6 +21,6 @@ When developing mobile apps, quitting is not desired unless the user is on the m
|
||||
It is important to note that by default, Godot apps have the built-in behavior to quit when quit is requested, this can be changed:
|
||||
|
||||
```python
|
||||
get_scene().set_auto_accept_quit(false)
|
||||
get_tree().set_auto_accept_quit(false)
|
||||
```
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# SceneMainLoop
|
||||
# SceneTree
|
||||
|
||||
### Introduction
|
||||
|
||||
@ -14,12 +14,12 @@ When initialization is complete, [OS](class_os) needs to be supplied a [MainLoop
|
||||
|
||||
The user program, or game, starts in the MainLoop. This class has a few methods, for initialization, idle (frame-syncronized callback), fixed (physics-synchronized callback), and input. Again, this is really low level and when making games in Godot, writing your own MainLoop does not even make sense.
|
||||
|
||||
### SceneMainLoop
|
||||
### SceneTree
|
||||
|
||||
One of the ways to explain how Godot works, is that it's a high level game engine over a low level middleware.
|
||||
The scene system is the game engine, while the [OS](class_os) and servers are the low level API.
|
||||
|
||||
In any case, the scene system provides it's own main loop to OS, [SceneMainLoop](class_scenemainloop).
|
||||
In any case, the scene system provides it's own main loop to OS, [SceneTree](class_scenemainloop).
|
||||
This is automatically instanced and set when running a scene, no need to do any extra work.
|
||||
|
||||
It's important to know that this class exists because it has a few important uses:
|
||||
@ -28,20 +28,20 @@ It's important to know that this class exists because it has a few important use
|
||||
* It contains information about the groups, and has means to call all nodes in a group, or get a list of them.
|
||||
* It contains some global state functionality, such as setting pause mode, or quitting the process.
|
||||
|
||||
When a node is part of the active scene, the [SceneMainLoop](class_scenemainloop) can be obtained by simply calling [Node.get_scene](class_node#get_scene)().
|
||||
When a node is part of the active scene, the [SceneTree](class_scenemainloop) can be obtained by simply calling [Node.get_tree](class_node#get_tree)().
|
||||
|
||||
### Root Viewport
|
||||
|
||||
The root [Viewport](class_viewport) is always a top of the scene. From a node, it can be obtained in two different ways:
|
||||
|
||||
```python
|
||||
get_scene().get_root() # access via scenemainloop
|
||||
get_tree().get_root() # access via scenemainloop
|
||||
get_node("/root") # access via absolute path
|
||||
```
|
||||
|
||||
This node contains the main viewport, anything that is a child of a [Viewport](class_viewport) is drawn inside of it by default, so it makes sense that the top of all nodes is always a node of this type, otherwise nothing would be seen!
|
||||
|
||||
While other viewports can be created in the scene (for split-screen effects and such), this one is the only one that is never created by the user. It's created automatically inside SceneMainLoop.
|
||||
While other viewports can be created in the scene (for split-screen effects and such), this one is the only one that is never created by the user. It's created automatically inside SceneTree.
|
||||
|
||||
### Active Scene
|
||||
|
||||
@ -61,7 +61,7 @@ Most node operations in Godot, such as drawing 2D, processing or getting notific
|
||||
### "Becoming Active" In Detail
|
||||
|
||||
1. A scene is loaded from disk or created by scripting.
|
||||
2. The root node of that scene (only one root, remember?) is added as either a child of the “root” Viewport (from SceneMainLoop), or to any child or grand-child of it.
|
||||
2. The root node of that scene (only one root, remember?) is added as either a child of the “root” Viewport (from SceneTree), or to any child or grand-child of it.
|
||||
3. Every node of the newly added scene, will receive the “enter_scene” notification ( _enter_scene() callback in GDScript) in top-to-bottom order.
|
||||
4. An extra notification, “ready” ( _ready() callback in GDScript) is provided for convenience, when a node and all it’s children are inside the active scene.
|
||||
5. When a scene (or part of it) is removed, they receive the “exit scene” rotification ( _exit_scene() callback in GDScript) in bottom-to-top order
|
||||
|
@ -53,26 +53,26 @@ func _ready():
|
||||
|
||||
```
|
||||
|
||||
This way, if the player, sneaking into the secret base, is discovered, all enemies can be notified about the alarm sounding, by using [SceneMainLoop.call_group](class_scenemainloop#call_group)():
|
||||
This way, if the player, sneaking into the secret base, is discovered, all enemies can be notified about the alarm sounding, by using [SceneTree.call_group](class_scenemainloop#call_group)():
|
||||
|
||||
```python
|
||||
|
||||
func _on_discovered():
|
||||
|
||||
get_scene().call_group(0,"guards","player_was_discovered")
|
||||
get_tree().call_group(0,"guards","player_was_discovered")
|
||||
|
||||
```
|
||||
|
||||
The above code calls the function "player_was_discovered" on every member of the group "guards".
|
||||
Optionally, it is possible to get the full list of "guards" nodes by calling [SceneMainLoop.get_nodes_in_group](class_scenemainloop#get_nodes_in_group)():
|
||||
Optionally, it is possible to get the full list of "guards" nodes by calling [SceneTree.get_nodes_in_group](class_scenemainloop#get_nodes_in_group)():
|
||||
|
||||
```python
|
||||
|
||||
var guards = get_scene().get_nodes_in_group("guards")
|
||||
var guards = get_tree().get_nodes_in_group("guards")
|
||||
|
||||
```
|
||||
|
||||
More will be added about [SceneMainLoop](class_scenemainloop) later.
|
||||
More will be added about [SceneTree](class_scenemainloop) later.
|
||||
|
||||
|
||||
### Notifications
|
||||
|
@ -69,7 +69,7 @@ extends Node
|
||||
var current_scene = null
|
||||
|
||||
func _ready():
|
||||
var root = get_scene().get_root()
|
||||
var root = get_tree().get_root()
|
||||
current_scene = root.get_child( root.get_child_count() -1 )
|
||||
|
||||
```
|
||||
@ -80,13 +80,13 @@ Next, is the function for changing scene. This function will erase the current s
|
||||
|
||||
func goto_scene(scene):
|
||||
# remove current scene from root and enqueue it for deletion
|
||||
get_scene().get_root().remove(current_scene)
|
||||
get_tree().get_root().remove(current_scene)
|
||||
current_scene.queue_free()
|
||||
|
||||
# load and add new scene to root
|
||||
var s = ResourceLoader.load(scene)
|
||||
current_scene = s.instance()
|
||||
get_scene().get_root().add_child(current_scene)
|
||||
get_tree().get_root().add_child(current_scene)
|
||||
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user