Place the New Node
Part of the Game Rules section of Coddy's Godot journey. Lesson 17 of 29.
A new block starts where its scene puts it. block.tscn places it in the middle, above the screen.
The new block is a node like any other, so set its position before you add it:
var block = block_scene.instantiate()
block.position = Vector2(500, -30)
add_child(block)Write block. in front of position. A bare position belongs to the node the script is on, here Main. Moving Main moves the whole game.
Challenge
EasyMake the block fall on the left.
- In
_ready(), setblock.positiontoVector2(160, -30). - Do it before
add_child(block).
Press Play: the block drops in from just above the screen at x = 160. Then Check.
Try it yourself
extends Node2D
var block_scene = preload("res://block.tscn")
func _ready():
var block = block_scene.instantiate()
add_child(block)
All lessons in Game Rules
4Spawning
A Packed ScenePlace the New NodeA Spawn FunctionSpawn on a TimerRandom PositionsRandom LanesPractice on your own: Godot playground