module
Eagle::SceneTree
Overview
The global tree of nodes that Eagle updates and draws every frame.
Everything you add under SceneTree.root gets its process, physics_process,
draw and input hooks called automatically. Use .change_scene to switch between
screens such as a title menu and a level, and groups to reach many nodes at once.
class Level < Node2D
def ready : Nil
3.times { |i| add(Sprite2D.new(Texture.new(Image.circle(8, Color::RED)), v2(100 + i * 50, 100)).add_to_group("enemies")) }
end
end
SceneTree.change_scene(Level.new)
SceneTree.call_group("enemies") { |n| n.queue_free }
SceneTree.paused = true # stops nodes whose process_mode is Pausable or Inherit
Defined in:
eagle/core/scene_tree.crClass Method Summary
-
.add(node : Node) : Node
Adds node to the root.
-
.call_group(name : String, & : Node -> ) : Nil
Yields every node in the group.
-
.change_scene(scene : Node) : Nil
Replaces the current scene with scene at the end of the frame.
-
.change_scene!(scene : Node) : Nil
Replaces the current scene immediately.
-
.current_scene : Node | Nil
The scene set by
.change_scene, if any. -
.defer(&block : -> ) : Nil
Runs the block at the end of the current frame, after all nodes have processed.
-
.group(name : String) : Array(Node)
Every node in the tree that belongs to the group name.
-
.node_count : Int32
Total number of nodes under the root, for debug overlays.
-
.paused=(v : Bool)
Pauses or resumes the tree.
-
.paused? : Bool
True while the tree is paused.
-
.root : Node
The top node.
Class Method Detail
Yields every node in the group. Safe even if the block removes nodes.
Replaces the current scene with scene at the end of the frame. The old scene is removed. Safe to call from inside the old scene's callbacks.
Replaces the current scene immediately. Prefer .change_scene unless you know no callbacks are running.
Runs the block at the end of the current frame, after all nodes have processed. Use it to change the tree safely from inside a callback.
Every node in the tree that belongs to the group name.
Pauses or resumes the tree. Paused nodes skip process and physics_process but still draw.
Nodes with ProcessMode::Always keep running, which suits pause menus.