Skip to content
0.2.0-dev Download ZIP
139 lines ·8.3 KB Raw
1<?xml version="1.0" encoding="UTF-8" ?>
2<class name="Node2D" inherits="CanvasItem" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and skew.
5 </brief_description>
6 <description>
7 A 2D game object, with a transform (position, rotation, and scale). All 2D nodes, including physics objects and sprites, inherit from Node2D. Use Node2D as a parent node to move, scale and rotate children in a 2D project. Also gives control of the node's render order.
8 [b]Note:[/b] Since both [Node2D] and [Control] inherit from [CanvasItem], they share several concepts from the class such as the [member CanvasItem.z_index] and [member CanvasItem.visible] properties.
9 </description>
10 <tutorials>
11 <link title="Custom drawing in 2D">$DOCS_URL/tutorials/2d/custom_drawing_in_2d.html</link>
12 <link title="All 2D Demos">https://github.com/godotengine/godot-demo-projects/tree/master/2d</link>
13 </tutorials>
14 <methods>
15 <method name="apply_scale">
16 <return type="void" />
17 <param index="0" name="ratio" type="Vector2" />
18 <description>
19 Multiplies the current scale by the [param ratio] vector.
20 </description>
21 </method>
22 <method name="get_angle_to" qualifiers="const" keywords="look_at">
23 <return type="float" />
24 <param index="0" name="point" type="Vector2" />
25 <description>
26 Returns the angle between the node and the [param point] in radians. See also [method look_at].
27 [url=https://raw.githubusercontent.com/godotengine/godot-docs/master/img/node2d_get_angle_to.png]Illustration of the returned angle.[/url]
28 </description>
29 </method>
30 <method name="get_relative_transform_to_parent" qualifiers="const">
31 <return type="Transform2D" />
32 <param index="0" name="parent" type="Node" />
33 <description>
34 Returns the [Transform2D] relative to this node's parent.
35 </description>
36 </method>
37 <method name="global_translate">
38 <return type="void" />
39 <param index="0" name="offset" type="Vector2" />
40 <description>
41 Adds the [param offset] vector to the node's global position.
42 </description>
43 </method>
44 <method name="look_at">
45 <return type="void" />
46 <param index="0" name="point" type="Vector2" />
47 <description>
48 Rotates the node so that its local +X axis points towards the [param point], which is expected to use global coordinates. This method is a combination of both [method rotate] and [method get_angle_to].
49 [param point] should not be the same as the node's position, otherwise the node always looks to the right.
50 </description>
51 </method>
52 <method name="move_local_x" keywords="translate_object_local">
53 <return type="void" />
54 <param index="0" name="delta" type="float" />
55 <param index="1" name="scaled" type="bool" default="false" />
56 <description>
57 Applies a local translation on the node's X axis with the amount specified in [param delta]. If [param scaled] is [code]false[/code], normalizes the movement to occur independently of the node's [member scale].
58 </description>
59 </method>
60 <method name="move_local_y" keywords="translate_object_local">
61 <return type="void" />
62 <param index="0" name="delta" type="float" />
63 <param index="1" name="scaled" type="bool" default="false" />
64 <description>
65 Applies a local translation on the node's Y axis with the amount specified in [param delta]. If [param scaled] is [code]false[/code], normalizes the movement to occur independently of the node's [member scale].
66 </description>
67 </method>
68 <method name="rotate">
69 <return type="void" />
70 <param index="0" name="radians" type="float" />
71 <description>
72 Applies a rotation to the node, in radians, starting from its current rotation. This is equivalent to [code]rotation += radians[/code].
73 </description>
74 </method>
75 <method name="to_global" qualifiers="const">
76 <return type="Vector2" />
77 <param index="0" name="local_point" type="Vector2" />
78 <description>
79 Transforms the provided local position into a position in global coordinate space. The input is expected to be local relative to the [Node2D] it is called on. e.g. Applying this method to the positions of child nodes will correctly transform their positions into the global coordinate space, but applying it to a node's own position will give an incorrect result, as it will incorporate the node's own transformation into its global position.
80 </description>
81 </method>
82 <method name="to_local" qualifiers="const">
83 <return type="Vector2" />
84 <param index="0" name="global_point" type="Vector2" />
85 <description>
86 Transforms the provided global position into a position in local coordinate space. The output will be local relative to the [Node2D] it is called on. e.g. It is appropriate for determining the positions of child nodes, but it is not appropriate for determining its own position relative to its parent.
87 </description>
88 </method>
89 <method name="translate">
90 <return type="void" />
91 <param index="0" name="offset" type="Vector2" />
92 <description>
93 Translates the node by the given [param offset] in local coordinates. This is equivalent to [code]position += offset[/code].
94 </description>
95 </method>
96 </methods>
97 <members>
98 <member name="global_position" type="Vector2" setter="set_global_position" getter="get_global_position">
99 Global position. See also [member position].
100 </member>
101 <member name="global_rotation" type="float" setter="set_global_rotation" getter="get_global_rotation">
102 Global rotation in radians. See also [member rotation].
103 </member>
104 <member name="global_rotation_degrees" type="float" setter="set_global_rotation_degrees" getter="get_global_rotation_degrees">
105 Helper property to access [member global_rotation] in degrees instead of radians. See also [member rotation_degrees].
106 </member>
107 <member name="global_scale" type="Vector2" setter="set_global_scale" getter="get_global_scale">
108 Global scale. See also [member scale].
109 </member>
110 <member name="global_skew" type="float" setter="set_global_skew" getter="get_global_skew">
111 Global skew in radians. See also [member skew].
112 </member>
113 <member name="global_transform" type="Transform2D" setter="set_global_transform" getter="get_global_transform">
114 Global [Transform2D]. See also [member transform].
115 </member>
116 <member name="position" type="Vector2" setter="set_position" getter="get_position" default="Vector2(0, 0)">
117 Position, relative to the node's parent. See also [member global_position].
118 </member>
119 <member name="rotation" type="float" setter="set_rotation" getter="get_rotation" default="0.0">
120 Rotation in radians, relative to the node's parent. See also [member global_rotation].
121 [b]Note:[/b] This property is edited in the inspector in degrees. If you want to use degrees in a script, use [member rotation_degrees].
122 </member>
123 <member name="rotation_degrees" type="float" setter="set_rotation_degrees" getter="get_rotation_degrees">
124 Helper property to access [member rotation] in degrees instead of radians. See also [member global_rotation_degrees].
125 </member>
126 <member name="scale" type="Vector2" setter="set_scale" getter="get_scale" default="Vector2(1, 1)">
127 The node's scale, relative to the node's parent. Unscaled value: [code](1, 1)[/code]. See also [member global_scale].
128 [b]Note:[/b] Negative X scales in 2D are not decomposable from the transformation matrix. Due to the way scale is represented with transformation matrices in Godot, negative scales on the X axis will be changed to negative scales on the Y axis and a rotation of 180 degrees when decomposed.
129 </member>
130 <member name="skew" type="float" setter="set_skew" getter="get_skew" default="0.0">
131 If set to a non-zero value, slants the node in one direction or another. This can be used for pseudo-3D effects. See also [member global_skew].
132 [b]Note:[/b] Skew is performed on the X axis only, and [i]between[/i] rotation and scaling.
133 [b]Note:[/b] This property is edited in the inspector in degrees. If you want to use degrees in a script, use [code]skew = deg_to_rad(value_in_degrees)[/code].
134 </member>
135 <member name="transform" type="Transform2D" setter="set_transform" getter="get_transform">
136 The node's [Transform2D], relative to the node's parent. See also [member global_transform].
137 </member>
138 </members>
139</class>