class
Eagle::Node2D
- Eagle::Node2D
- Eagle::Node
- Reference
- Object
Overview
A node with a 2D position, rotation and scale. It is the base of every 2D game object.
Children move with their parent: a gun added to a ship turns when the ship turns. Local
values (#position, #rotation, #scale) are relative to the parent, and the global_*
methods give world-space values.
class Ship < Node2D
def ready : Nil
add(Polygon2D.new([v2(12, 0), v2(-8, -8), v2(-8, 8)], Color::WHITE))
add(Node2D.new("Muzzle", position: v2(14, 0)))
end
def process(dt : Float32) : Nil
rotate(Input.axis("left", "right") * 3 * dt)
translate(forward * 120 * dt) # forward follows rotation
muzzle = get_node("Muzzle", Node2D).global_position # where bullets spawn
end
end
#modulate tints the node and all its children, so fading a whole character out is one
line. Set top_level to ignore the parent's transform.
Direct Known Subclasses
- Eagle::AudioPlayer2D
- Eagle::Camera2D
- Eagle::CollisionObject2D
- Eagle::Control
- Eagle::Line2D
- Eagle::Particles2D
- Eagle::Polygon2D
- Eagle::RayCast2D
- Eagle::Sprite2D
- Eagle::TileMap
Defined in:
eagle/nodes/node2d.crConstructors
-
.new(name : String = "", position : Eagle::Vec2 = Vec2::ZERO, rotation : Float32 = 0_f32, scale : Eagle::Vec2 = Vec2::ONE)
Creates a 2D node at position.
Instance Method Summary
-
#direction_to(other : Node2D) : Vec2
Unit vector pointing from this node toward other.
-
#distance_to(other : Node2D) : Float32
Distance to another 2D node, in world space.
-
#down : Vec2
The unit vector 90° clockwise from
#right. -
#forward : Vec2
Same as
#right: the direction the node faces. -
#global_position : Vec2
Position in world space.
-
#global_position=(p : Vec2)
Moves the node so it ends up at p in world space.
-
#global_rotation : Float32
Rotation in world space.
-
#global_scale : Vec2
Scale in world space.
-
#global_transform : Transform2D
The transform from this node's space to world space.
-
#look_at(target : Vec2) : Nil
Rotates the node to face a world-space point.
-
#modulate : Color
Color multiplied into this node and all of its children.
-
#modulate=(modulate : Color)
Color multiplied into this node and all of its children.
-
#parent_2d : Node2D | Nil
The nearest ancestor that is a
Node2D, ornil. -
#position : Vec2
Position relative to the parent, in points.
-
#position=(p : Vec2)
Sets the position.
-
#right : Vec2
The unit vector this node faces, in world space.
-
#rotate(rad : Number) : Nil
Adds rad radians to the rotation.
-
#rotation : Float32
Rotation relative to the parent, in radians.
-
#rotation=(rotation : Float32)
Rotation relative to the parent, in radians.
-
#rotation_degrees : Float32
Rotation in degrees.
-
#rotation_degrees=(d : Number)
Sets the rotation in degrees.
-
#scale : Vec2
Scale relative to the parent.
-
#scale=(s : Vec2)
Sets the scale per axis.
-
#scale=(s : Number)
Sets a uniform scale.
-
#to_global(local : Vec2) : Vec2
Converts a local point into world space.
-
#to_local(global : Vec2) : Vec2
Converts a world-space point into this node's local space.
-
#top_level=(top_level : Bool)
When true, the node ignores its parent's transform and positions itself in world space.
-
#top_level? : Bool
When true, the node ignores its parent's transform and positions itself in world space.
-
#transform : Transform2D
The local transform built from position, rotation and scale.
-
#transform=(t : Transform2D)
Sets position, rotation and scale from a transform.
-
#translate(x : Number, y : Number) : Nil
Moves the node by x, y in parent space.
-
#translate(v : Vec2) : Nil
Moves the node by v in parent space.
-
#x : Float32
The x position.
-
#x=(v : Number)
Sets the x position.
-
#y : Float32
The y position.
-
#y=(v : Number)
Sets the y position.
Instance methods inherited from class Eagle::Node
<<(child : Node) : self
<<,
[](path : String) : Node
[],
[]?(path : String) : Node | Nil
[]?,
add(child : Node) : Nodeadd(*children : Node) : Nil add, add_child(child : Node) : Node add_child, add_to_group(group : String) : self add_to_group, ancestor_of?(node : Node) : Bool ancestor_of?, can_process? : Bool can_process?, child?(name : String) : Node | Nil child?, child_added : Eagle::Emitter(Node) child_added, child_count : Int32 child_count, child_removed : Eagle::Emitter(Node) child_removed, children : Array(Eagle::Node) children, children_of(type : T.class) : Array(T) forall T children_of, clear_children : Nil clear_children, draw(g : Graphics) : Nil draw, dump(io : IO = STDOUT, indent = 0) : Nil dump, each_ancestor(& : Node -> ) : Nil each_ancestor, each_child(& : Node -> ) : Nil each_child, each_descendant(&block : Node -> ) : Nil each_descendant, emit_child_added(*args) : Nil emit_child_added, emit_child_removed(*args) : Nil emit_child_removed, emit_tree_entered(*args) : Nil emit_tree_entered, emit_tree_exited(*args) : Nil emit_tree_exited, enter_tree : Nil enter_tree, exit_tree : Nil exit_tree, find(name : String) : Node | Nil find, find_all(type : T.class) : Array(T) forall T find_all, first_child : Node | Nil first_child, free : Nil free, get_node(path : String, type : T.class) : T forall T
get_node(path : String) : Node get_node, get_node?(path : String) : Node | Nil get_node?, groups : Set(String) groups, in_group?(group : String) : Bool in_group?, in_tree? : Bool in_tree?, input(event : Event) : Nil input, name : String name, name=(name : String) name=, on_child_added(&block : Node -> Nil) : Proc(Node, Nil) on_child_added, on_child_removed(&block : Node -> Nil) : Proc(Node, Nil) on_child_removed, on_tree_entered(&block : -> Nil) : Proc(Nil) on_tree_entered, on_tree_exited(&block : -> Nil) : Proc(Nil) on_tree_exited, parent : Node | Nil parent, path : String path, physics_process(dt : Float32) : Nil physics_process, process(dt : Float32) : Nil process, process_mode : Eagle::Node::ProcessMode process_mode, process_mode=(process_mode : Eagle::Node::ProcessMode) process_mode=, queue_free : Nil queue_free, queued_free? : Bool queued_free?, ready : Nil ready, ready_called? : Bool ready_called?, remove(child : Node) : Nil remove, remove_child(child : Node) : Nil remove_child, remove_from_group(group : String) : Nil remove_from_group, remove_from_parent : Nil remove_from_parent, resized(width : Int32, height : Int32) : Nil resized, root : Node root, to_s(io : IO) : Nil to_s, tree_entered : Eagle::Emitter() tree_entered, tree_exited : Eagle::Emitter() tree_exited, visible=(visible : Bool) visible=, visible? : Bool visible?, z_index : Int32 z_index, z_index=(z_index : Int32) z_index=
Constructor methods inherited from class Eagle::Node
new(name : String = "")
new
Constructor Detail
Creates a 2D node at position.
Instance Method Detail
Rotates the node to face a world-space point.
turret = Node2D.new
turret.look_at(Input.mouse)
Rotation relative to the parent, in radians. Positive is clockwise on screen.
Rotation relative to the parent, in radians. Positive is clockwise on screen.
When true, the node ignores its parent's transform and positions itself in world space.
When true, the node ignores its parent's transform and positions itself in world space.