Godot Version
v4.3.stable.fedora [77dcf97d8]
Question
I’m trying to get to grips with the basics, and the reference has so many verbs and nouns that I don’t even know what I’m really looking for there, so apologies for such a basic question. Basically right now I’m trying to make a basic Flappy Bird type of game, and to that end I’d like to periodically generate a column of terrain with its looks based on a TileSet where I’ve defined the peering bits, carve out the middle toe make a hole for the player to pass through, and then send the terrain moving right across the screen. I’ve read the Getting Started section of the documentation, but that’s still left me somewhat green, and so I don’t really know what I should be looking for in the docs to do this thing. Any help pointing me in the right direction would be much appreciated.
1 Like
Tile maps are based on grids, not suit for a Flappy Brid game. I’m not sure why you’re using tile maps, but if you making a Flappy Bird, you need instantiating scenes.
This is a typical pipe code you would use:
extends Node2D
const SPEED: float = 100
func process(delta: float) -> void:
position.x -= SPEED * delta
if position.x < 3000: # Assuming 3000 is the screen left side limit
queue_free() # Delete this node
And the obstacle manager node, creating obstacles at its position
extends Node2D
@export var pipe: Scene
func create(pos: Vector2) -> void:
var node := pipe.instantiate()
node.position = pos
add_child(node)
func create_pair(y: float) -> void:
# Your implementation
Look up the TileMap.set_cell()
method - It’ll help you decide how to programmatically place cells. Plus the SceneTreeTimer for periodic placement.
Here’s a short example of code applying them, but you’ll need to modify it to apply it to your own game:
# ok so this script goes on ur main scene or whatever you got
var tilemap: TileMap # this is your tilemap node that u added to the scene
func _ready():
# grab the tilemap node - make sure u named it "TileMap" in the scene tree!!
tilemap = $TileMap
# lets start making tubes!
start_spawning()
func start_spawning():
# make a new timer to spawn stuff periodically
var spawn_timer = Timer.new()
spawn_timer.wait_time = 2.0 # spawns a new tube every 2 secs
# when timer goes off, run our spawn_column function
spawn_timer.timeout.connect(spawn_column)
# gotta add the timer to the scene or it wont work lol
add_child(spawn_timer)
spawn_timer.start()
func spawn_column():
# this is where we'll start placing our new tube
var start_x = 10
# k now lets make the actual tube
# for example here gonna make it 10 tiles high
for y in range(0, 10):
# this places each tile - dont worry too much about the numbers
# just know that were putting tiles at different y positions
tilemap.set_cell(0, Vector2i(start_x, y), 0, Vector2i(0, 0))
# now lets make a hole in the middle so the bird can fly thru
var hole_start = 4 # start hole about halfway up
for y in range(hole_start, hole_start + 3): # make it 3 tiles big
# erase some tiles to make the hole
tilemap.erase_cell(0, Vector2i(start_x, y))
# thats it! now u just need to make em move left and clean up old ones
# but this should get u started :D
Thanks for the help! I was able to get a little further along, but not quite all the way to where I wanted. I’ll keep exploring and then come back to this later.
A much easier approach would be to just spawn a background periodically Infront of the player outside the viewport, over and over. And spawn on it your pillars at a randomly set height within range, with a gap between them.
That’s as barebones as it gets without using a tilemap.