PathFollow2D¶
Inherits: Node2D < CanvasItem < Node < Object
Category: Core
Member Functions¶
bool | get_cubic_interpolation ( ) const |
float | get_h_offset ( ) const |
float | get_offset ( ) const |
float | get_unit_offset ( ) const |
float | get_v_offset ( ) const |
bool | has_loop ( ) const |
bool | is_rotating ( ) const |
void | set_cubic_interpolation ( bool enable ) |
void | set_h_offset ( float h_offset ) |
void | set_loop ( bool loop ) |
void | set_offset ( float offset ) |
void | set_rotate ( bool enable ) |
void | set_unit_offset ( float unit_offset ) |
void | set_v_offset ( float v_offset ) |
Description¶
This node takes its parent Path2D, and returns the coordinates of a point within it, given a distance from the first vertex.
It is useful for making other nodes follow a path, without coding the movement pattern. For that, the nodes must be descendants of this node. Then, when setting an offset in this node, the descendant nodes will move accordingly.
Member Function Description¶
- bool get_cubic_interpolation ( ) const
This method returns whether the position between two cached points (see set_cubic_interpolation) is interpolated linearly, or cubicly.
- float get_h_offset ( ) const
Returns the horizontal displacement this node has from its parent Path2D.
- float get_offset ( ) const
Returns the distance along the path in pixels.
- float get_unit_offset ( ) const
Returns the distance along the path as a number in the range 0.0 (for the first vertex) to 1.0 (for the last).
- float get_v_offset ( ) const
Returns the vertical displacement this node has from its parent Path2D.
- bool has_loop ( ) const
Returns whether this node wraps its offsets around, or truncates them to the path ends.
- bool is_rotating ( ) const
Returns whether this node rotates to follow the path.
- void set_cubic_interpolation ( bool enable )
The points along the Curve2D of the Path2D are precomputed before use, for faster calculations. The point at the requested offset is then calculated interpolating between two adjacent cached points. This may present a problem if the curve makes sharp turns, as the cached points may not follow the curve closely enough.
There are two answers to this problem: Either increase the number of cached points and increase memory consumption, or make a cubic interpolation between two points at the cost of (slightly) slower calculations.
This method controls whether the position between two cached points is interpolated linearly, or cubicly.
- void set_h_offset ( float h_offset )
Moves this node horizontally. As this node’s position will be set every time its offset is set, this allows many PathFollow2D to share the same curve (and thus the same movement pattern), yet not return the same position for a given path offset.
A similar effect may be achieved moving this node’s descendants.
- void set_loop ( bool loop )
If set, any offset outside the path’s length (whether set by set_offset or set_unit_offset will wrap around, instead of stopping at the ends. Set it for cyclic paths.
- void set_offset ( float offset )
Sets the distance from the first vertex, measured in pixels along the path. This sets this node’s position to a point within the path.
- void set_rotate ( bool enable )
If set, this node rotates to follow the path, making its descendants rotate.
- void set_unit_offset ( float unit_offset )
Sets the distance from the first vertex, considering 0.0 as the first vertex and 1.0 as the last. This is just another way of expressing the offset within the path, as the offset supplied is multiplied internally by the path’s length.
- void set_v_offset ( float v_offset )
Moves the PathFollow2D vertically, for the same reasons of set_h_offset.