Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Curve

Inherits: Resource < RefCounted < Object

A mathematical curve.

描述

This resource describes a mathematical curve by defining a set of points and tangents at each point. By default, it ranges between 0 and 1 on the Y axis and positions points relative to the 0.5 Y position.

See also Gradient which is designed for color interpolation. See also Curve2D and Curve3D.

属性

int

bake_resolution

100

float

max_value

1.0

float

min_value

0.0

int

point_count

0

Methods

int

add_point ( Vector2 position, float left_tangent=0, float right_tangent=0, TangentMode left_mode=0, TangentMode right_mode=0 )

void

bake ( )

void

clean_dupes ( )

void

clear_points ( )

TangentMode

get_point_left_mode ( int index ) const

float

get_point_left_tangent ( int index ) const

Vector2

get_point_position ( int index ) const

TangentMode

get_point_right_mode ( int index ) const

float

get_point_right_tangent ( int index ) const

void

remove_point ( int index )

float

sample ( float offset ) const

float

sample_baked ( float offset ) const

void

set_point_left_mode ( int index, TangentMode mode )

void

set_point_left_tangent ( int index, float tangent )

int

set_point_offset ( int index, float offset )

void

set_point_right_mode ( int index, TangentMode mode )

void

set_point_right_tangent ( int index, float tangent )

void

set_point_value ( int index, float y )


信号

range_changed ( )

Emitted when max_value or min_value is changed.


Enumerations

enum TangentMode:

TangentMode TANGENT_FREE = 0

The tangent on this side of the point is user-defined.

TangentMode TANGENT_LINEAR = 1

The curve calculates the tangent on this side of the point as the slope halfway towards the adjacent point.

TangentMode TANGENT_MODE_COUNT = 2

The total number of available tangent modes.


Property Descriptions

int bake_resolution = 100

  • void set_bake_resolution ( int value )

  • int get_bake_resolution ( )

The number of points to include in the baked (i.e. cached) curve data.


float max_value = 1.0

  • void set_max_value ( float value )

  • float get_max_value ( )

The maximum value the curve can reach.


float min_value = 0.0

  • void set_min_value ( float value )

  • float get_min_value ( )

The minimum value the curve can reach.


int point_count = 0

  • void set_point_count ( int value )

  • int get_point_count ( )

The number of points describing the curve.


Method Descriptions

int add_point ( Vector2 position, float left_tangent=0, float right_tangent=0, TangentMode left_mode=0, TangentMode right_mode=0 )

Adds a point to the curve. For each side, if the *_mode is TANGENT_LINEAR, the *_tangent angle (in degrees) uses the slope of the curve halfway to the adjacent point. Allows custom assignments to the *_tangent angle if *_mode is set to TANGENT_FREE.


void bake ( )

Recomputes the baked cache of points for the curve.


void clean_dupes ( )

Removes duplicate points, i.e. points that are less than 0.00001 units (engine epsilon value) away from their neighbor on the curve.


void clear_points ( )

Removes all points from the curve.


TangentMode get_point_left_mode ( int index ) const

Returns the left TangentMode for the point at index.


float get_point_left_tangent ( int index ) const

Returns the left tangent angle (in degrees) for the point at index.


Vector2 get_point_position ( int index ) const

Returns the curve coordinates for the point at index.


TangentMode get_point_right_mode ( int index ) const

Returns the right TangentMode for the point at index.


float get_point_right_tangent ( int index ) const

Returns the right tangent angle (in degrees) for the point at index.


void remove_point ( int index )

Removes the point at index from the curve.


float sample ( float offset ) const

Returns the Y value for the point that would exist at the X position offset along the curve.


float sample_baked ( float offset ) const

Returns the Y value for the point that would exist at the X position offset along the curve using the baked cache. Bakes the curve's points if not already baked.


void set_point_left_mode ( int index, TangentMode mode )

Sets the left TangentMode for the point at index to mode.


void set_point_left_tangent ( int index, float tangent )

Sets the left tangent angle for the point at index to tangent.


int set_point_offset ( int index, float offset )

Sets the offset from 0.5.


void set_point_right_mode ( int index, TangentMode mode )

Sets the right TangentMode for the point at index to mode.


void set_point_right_tangent ( int index, float tangent )

Sets the right tangent angle for the point at index to tangent.


void set_point_value ( int index, float y )

Assigns the vertical position y to the point at index.