Member Functions

Color Color8 ( int r8, int g8, int b8, int a8=255 )
Color ColorN ( String name, float alpha=1.0 )
float abs ( float s )
float acos ( float s )
float asin ( float s )
void assert ( bool condition )
float atan ( float s )
float atan2 ( float x, float y )
Variant bytes2var ( PoolByteArray bytes )
Vector2 cartesian2polar ( float x, float y )
float ceil ( float s )
String char ( int ascii )
float clamp ( float value, float min, float max )
Object convert ( Variant what, int type )
float cos ( float s )
float cosh ( float s )
float db2linear ( float db )
float decimals ( float step )
float dectime ( float value, float amount, float step )
float deg2rad ( float deg )
Object dict2inst ( Dictionary dict )
float ease ( float s, float curve )
float exp ( float s )
float floor ( float s )
float fmod ( float x, float y )
float fposmod ( float x, float y )
Object funcref ( Object instance, String funcname )
int hash ( Variant var )
Dictionary inst2dict ( Object inst )
Object instance_from_id ( int instance_id )
float inverse_lerp ( float from, float to, float weight )
bool is_inf ( float s )
bool is_nan ( float s )
int len ( Variant var )
float lerp ( float from, float to, float weight )
float linear2db ( float nrg )
Object load ( String path )
float log ( float s )
float max ( float a, float b )
float min ( float a, float b )
int nearest_po2 ( int value )
Variant parse_json ( String json )
Vector2 polar2cartesian ( float r, float th )
float pow ( float x, float y )
Resource preload ( String path )
void print ( ) vararg
void print_stack ( )
void printerr ( ) vararg
void printraw ( ) vararg
void prints ( ) vararg
void printt ( ) vararg
float rad2deg ( float rad )
float rand_range ( float from, float to )
Array rand_seed ( int seed )
float randf ( )
int randi ( )
void randomize ( )
Array range ( ) vararg
float range_lerp ( float value, float istart, float istop, float ostart, float ostop )
float round ( float s )
void seed ( int seed )
float sign ( float s )
float sin ( float s )
float sinh ( float s )
float sqrt ( float s )
float stepify ( float s, float step )
String str ( ) vararg
Variant str2var ( String string )
float tan ( float s )
float tanh ( float s )
String to_json ( Variant var )
bool type_exists ( String type )
int typeof ( Variant what )
String validate_json ( String json )
PoolByteArray var2bytes ( Variant var )
String var2str ( Variant var )
Object weakref ( Object obj )
float wrapf ( float value, float min, float max )
int wrapi ( int value, int min, int max )
GDScriptFunctionState yield ( Object object=null, String signal=”” )

Numeric Constants

  • PI = 3.141593 — Constant that represents how many times the diameter of a circle fits around its perimeter.
  • TAU = 6.283185 — The circle constant, the circumference of the unit circle.
  • INF = inf — A positive infinity. (For negative infinity, use -INF).
  • NAN = nan — Macro constant that expands to an expression of type float that represents a NaN.

The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the square root of negative numbers or the result of 0/0.

 

1. GDScript 클래스에서 지원하는 메서드 함수 리스트.

2. ColorN() 함수에서 지원하는 컬러이름 목록은 다음과 같다.

“aliceblue”, “antiquewhite”, “aqua”, “aquamarine”, “azure”, “beige”, “bisque”, “black”, “blanchedalmond”, “blue”, “blueviolet”, “brown”, “burlywood”, “cadetblue”, “chartreuse”, “chocolate”, “coral”, “cornflower”, “cornsilk”, “crimson”, “cyan”, “darkblue”, “darkcyan”, “darkgoldenrod”, “darkgray”, “darkgreen”, “darkkhaki”, “darkmagenta”, “darkolivegreen”, “darkorange”, “darkorchid”, “darkred”, “darksalmon”, “darkseagreen”, “darkslateblue”, “darkslategray”, “darkturquoise”, “darkviolet”, “deeppink”, “deepskyblue”, “dimgray”, “dodgerblue”, “firebrick”, “floralwhite”, “forestgreen”, “fuchsia”, “gainsboro”, “ghostwhite”, “gold”, “goldenrod”, “gray”, “webgray”, “green”, “webgreen”, “greenyellow”, “honeydew”, “hotpink”, “indianred”, “indigo”, “ivory”, “khaki”, “lavender”, “lavenderblush”, “lawngreen”, “lemonchiffon”, “lightblue”, “lightcoral”, “lightcyan”, “lightgoldenrod”, “lightgray”, “lightgreen”, “lightpink”, “lightsalmon”, “lightseagreen”, “lightskyblue”, “lightslategray”, “lightsteelblue”, “lightyellow”, “lime”, “limegreen”, “linen”, “magenta”, “maroon”, “webmaroon”, “mediumaquamarine”, “mediumblue”, “mediumorchid”, “mediumpurple”, “mediumseagreen”, “mediumslateblue”, “mediumspringgreen”, “mediumturquoise”, “mediumvioletred”, “midnightblue”, “mintcream”, “mistyrose”, “moccasin”, “navajowhite”, “navyblue”, “oldlace”, “olive”, “olivedrab”, “orange”, “orangered”, “orchid”, “palegoldenrod”, “palegreen”, “paleturquoise”, “palevioletred”, “papayawhip”, “peachpuff”, “peru”, “pink”, “plum”, “powderblue”, “purple”, “webpurple”, “rebeccapurple”, “red”, “rosybrown”, “royalblue”, “saddlebrown”, “salmon”, “sandybrown”, “seagreen”, “seashell”, “sienna”, “silver”, “skyblue”, “slateblue”, “slategray”, “snow”, “springgreen”, “steelblue”, “tan”, “teal”, “thistle”, “tomato”, “turquoise”, “violet”, “wheat”, “white”, “whitesmoke”, “yellow”, “yellowgreen”.

 

<참고>
http://docs.godotengine.org/en/3.0/classes/class_@gdscript.html

extends Spatial

var camera_distance = 2

func _ready():
	set_process(true)

	$Spatial/Spatial/Camera.translation = camera_distance * Vector3(0, 5, 5)
	$Spatial/Spatial/Camera.rotation_degrees = Vector3(-35, 0, 0)
	
func _process(delta):
	# Left & Right Rotation
	if Input.is_key_pressed(KEY_Q):
		$Spatial.rotate_y(5 * delta)
	elif Input.is_key_pressed(KEY_E):
		$Spatial.rotate_y(-5 * delta)

	# Up & Down Rotation
	if Input.is_key_pressed(KEY_W):
		$Spatial/Spatial.rotate_x(5 * delta)
	elif Input.is_key_pressed(KEY_S):
		$Spatial/Spatial.rotate_x(-5 * delta)

	# Zoomin & Zoomout
	if Input.is_key_pressed(KEY_EQUAL):
		$Spatial.set_scale($Spatial.get_scale() - Vector3(0.8, 0.8, 0.8) * delta)
	elif Input.is_key_pressed(KEY_MINUS):
		$Spatial.set_scale($Spatial.get_scale() + Vector3(0.8, 0.8, 0.8) * delta)

 

<참고>
http://www.bitoutsidethebox.com/godot-tutorial-5-2-axis-gimbal-camera-for-3d-games/

extends Node
...
signal my_signal


func _ready():
    connect("my_signal", self, "signal_handler")
    ...
    var otherNode = get_node("someNode")
    otherNode.connect("my_signal", self, "signal_handler")

func SomeFunc():
    ...
    # causes self.signal_handler() to be called
    emit_signal("my_signal")
    ...

func signal_handler():
    ...

 

[참고] https://godotengine.org/qa/3218/how-to-create-a-custom-signal-in-gdscript

Scene 편집 도구를 이용해도 되지만, GD Script만으로 코딩을 하고 싶을 경우(?)에는 아래 예제를 참고하여 작성하면 된다.

extends Node

func _ready():
	
	var timer = Timer.new()
	add_child(timer)

	timer.connect("timeout", self, "_on_timeout")

	timer.set_wait_time(10)
	timer.start()
	
func _on_timeout():
	
	print("Time out!")

 

[참고] http://docs.godotengine.org/en/3.0/classes/class_timer.html

RigidBody2D에서 총알(Bullet)을 발사하여 벽(Block)에 충돌하였을 경우, 충돌한 객체의 정보를 얻어내기 위해서는 func _ready() 안에 다음 code를 추가한다.

func _ready():
    set_contact_monitor(true)
    set_max_contacts_reported(5) # 0보다 큰 정수를 지정해주면 된다.

그다음 편집기에서 signals에서 함수를 연결하면 되지만, 직접 Gdscript에서 code를 추가하여보자. 그렇기 위해선 _ready() 함수 루틴에 다음과 같이 signal을 연결하는 code를 추가한다.

func _ready():
    set_contact_monitor(true)
    set_max_contacts_reported(5)
    connect("body_entered", self, "collision_detected")

그리고 collision_detected() 함수를 작성한다.

func collision_detected(obj):
    print(self.get_name(), " is colliding with ", obj.get_name())

더 자세한 정보를 얻고 싶을때는 get_colliding_bodies()를 이용하면 된다.

 

<참고>
 https://www.reddit.com/r/godot/comments/3ofhwj/how_can_i_use_body_enter_function/

일반적인 resource들은 load() 혹은 preload()를 이용하여 불러올 수 있다.

예)

var res1 = load("res://sample1.png")

var res2 = preload("res://sample2.png")

 

scene을 불러올 때는 PackedScene.instance()를 이용하면 된다.

예)

var bullet = preload("res://bullet.tscn").instance()

add_child(bullet)

인스턴스(혹은 노드)를 생성할 때 관리를 위해서 그룹화를 하는 경우가 생기는데, 그러한 경우 그룹 안에 몇개의 인스턴스가 생성되어 있는지 확인하고자 할 경우 다음과 같이 하면 된다.

 

get_tree().get_nodes_in_group("그룹명").size()

 

보다 자세한 것은 SceneTree.get_nodes_in_group을 참조하면 된다.

+ Recent posts