/Godot-FAQ

frequrently asked questions about godot that I need a reference to

Godot Reference

Topics I need to cover

How to save a file

How to publish a game

How to make a sprite have pathfinding

How to add an item in a grid container

How to show the amount of similar items in a item menu

How to create enemy AI

how to fix blurry sprites

[how to get children nodes from a parent][get_children]

how to use parallax scrolling

tween transition types

tween ease types

how to use the tween animation

how to turn off the collision of a node/object

How to clear/delete a node from a scene

How to transition to another scene

how to print something to console

how to get screen size

how to get a position of a node

how to get a size of a texture/sprite

how to check a type of node

how to create an instance of an object

[how to create a timer in gdscript][timer-script]


how to fix blurry sprites

View Content

reference

  1. Click on the image in FileSystem folder

  2. In the import tab on right of the screen disable

  • Filter
  • Mipmaps
  • Anisotropic
  1. Now click on the button that says Reimport

go back 🏠

how to create a timer in gdscript

View Content
onready var collection = $collection
var timer  = Timer.new() # creates a new instance of a timer

func _ready():
	timer.set_one_shot(true) # make sure the time doesn't repeat
	timer.set_wait_time(5) # set's the countdown time in seconds
	timer.connect("timeout", self, "on_timeout") # when the timer ends it call the function on_timeout
	collection.add_child(timer)#this adds the timer in a node called collection
	timer.start() #this starts the timer when you
	pass

func _process(delta):

	if paused:
		print(timer.time_left) #if paused is true, it will print out the remaining time

	pass



func on_timeout():
	print("foo") # after the time end it will print into the console foo

go back 🏠

how to create an instance of an object

View Content
var brick = bricks.instance()
# If I preloaded an object, this will create the object so that I can put it inside
# the scene

go back 🏠

how to check a type of node

View Content
## this checks if the node is a Position2D type
if node is Position2D :
	print("k")

go back 🏠

how to get children from a parent

View Content

reference

for node in collection.get_children():
	print(node.name)

go back 🏠

how to use parallax scrolling

View Content

reference

  1. Add a node called ParallaxBackground

  2. Select ParallaxBackground and add a child node called ParallaxLayer

  3. Select ParallaxLayer and a add child node that can either be a TileMap or a Sprite.

  4. In the options of the ParallaxLayer there is an called Scale. It has x and y coordinates, and this is the place where you will create the parallax effect. If you want the parallax scrolling to only happen horizontally then change the x coordinate. The default value is 1, but if you make it less than (for example: 0.5), the parallax effect will be more apparent.

  5. There are other options like mirroring which will duplicate the image in the ParallaxLayer, and the offset option that position the image. But I haven't really used them that much

go back 🏠

tween ease types

View Content

reference

Ease Type Value
EASE_IN 0
EASE_OUT 1
EASE_IN_OUT 2
EASE_OUT_IN 3

go back 🏠

tween transition type

View Content

reference

Transition Type Value
TRANS_LINEAR 0
TRANS_SINE 1
TRANS_QUINT 2
TRANS_QUART 3
TRANS_QUAD 4
TRANS_EXPO 5
TRANS_ELASTIC 6
TRANS_CUBIC 7
TRANS_CIRC 8
TRANS_BOUNCE 9
TRANS_BACK 10

go back 🏠

how to use the tween animation

View Content

reference

There are many ways to change the property of a node, so these are a couple of examples of how to change it

syntax $Tween.interpolate_property(Object, property, initial value, final value, duration time, transition type, ease type, delay time)

$Tween.interpolate_property($Sprite,"modulate", Color(1,1,1,1), Color(1,1,1,0),0.3, Tween.TRANS_QUAD, Tween.EASE_OUT )

go back 🏠

how to turn off a collision of a node

View Content

reference

Method 1

# when the potion collides with a body named isaiah
# shape_owner_clear_shapes will clear all the shapes as long as you have the owner id
# which will usually be 0
func _on_potion_body_entered(body):
	if body.get("name") == "isaiah":
		shape_owner_clear_shapes(0)
	pass

Method 2

# when the potion collides with a body named isaiah
# shape_owner_set_disabled will disable it as long as you have the boolean set to true
# and the owner id of collision shape which will be 0
func _on_potion_body_entered(body):
	if body.get("name") == "isaiah":
		shape_owner_set_disabled(0,true)
	pass

go back 🏠

how to clear a node from a scene

View Content

You usually do this when you are using signals, but I guess you can do that in any other function

func on_gem_area_enter(area):
  if area.get("name") == "player":
    queue_free() #this will delete the node which is a gem

go back 🏠

How to transition to another scene

View Content
get_tree().change_scene("res://World2.tscn")

go back 🏠

how to get a size of a texture/sprite

View Content
var sprite_size = get_texture().get_size()

go back 🏠

how to get a position of a node

View Content
print(get_pos())

go back 🏠

how to get screen size

View Content
var screensize = get_viewport_rect().size

go back 🏠

how to print something to console

print("someting to console")