Godot Version
4.5
Question
What would be the best way to spawn platforms in an infinite platformer? It’s going to be like Flappy Bird but then vertically where you’re constrained by the screen width. I see advantages of just using StaticBody2D’s, code-wise they’re probably the easiest as you could just basically spawn them on a random y between the left and right of the screen if you wanted to.
But advantages of TileMaps is that they have one-way collisions built in, which I’d really like for my platformer, and that they’re specifically built for platformers so you can easily have more diversity. How would I do that?
1 Like
I think you would have to be more careful with your auto-generation than just random y placements. That could go wrong dramatically.
As for tilemaps, you would generate a tile and add it to the tilemap at whatever position. As the camera scrolled up to it, it would appear. This would normally be done in chunks, and you would have a chunk generator to generate and load the chunks, and unload them once they went off screen or beyond a certain range.
How you do this exactly, would depend entirely on your game vision and gameplay and design ideas. Lets say you were doing DonkeyKong style. Your generator would generate diagonally sloped platforms with carefully spaced random ladders and barrel spawners etc. Lets say a diagonal platform ‘layer’ is 300px high, your chunks would be screen width by 300px chunks, so you could then just stack them as they are generated.
Anyway, doing this for tilemaps is more than do-able. Especially because your description is limited to vertical movement only. An open world is much harder because you have to be able to back track over previously loaded areas. Maps based on noise like perlin noise are good for this, as you don’t have to save them because, as long as you don’t use any random generation, they can always be recreated on demand.
Good luck with it, auto generation is great fun to code, even though it can seem tricky at first, when you get going with it, the results can be amazing as entire worlds based on a single seed open up around you!
1 Like
What can exactly go wrong? I’m doing a game jam and this was one of the main features I had to implement, so with a tight deadline I just started with the StaticBody implementation as that looked the most feasible to me.
This is what I have right now (no random y generation yet as I started to code around half an hour ago)
The code might be slightly spaghetti, I’m a beginner lol.
class_name PlatformSpawner extends Node2D
@export var platform_scene: PackedScene
@onready var camera_2d = $"../Player/Camera2D"
@onready var player = $"../Player"
@onready var player_collision_shape_node = player.get_node("CollisionShape2D")
@onready var player_collision_shape = player_collision_shape_node.shape
var y_pos := 0
func spawn_platforms(amount: int) -> void:
var camera_size = get_viewport_rect().size * camera_2d.zoom
var camera_rect = Rect2(camera_2d.get_screen_center_position() - camera_size / 2, camera_size)
var height_addition = 5
for i in amount:
var height = player_collision_shape.size.y * player_collision_shape_node.global_scale.y * height_addition
y_pos = camera_rect.end.y - height
var platform = platform_scene.instantiate()
platform.position.y = y_pos
height_addition += 3
add_child(platform)
func _on_game_manager_game_started() -> void:
spawn_platforms(4)
Good luck in your game jam! I have been meaning to do one myself for ages but have never been able to commit to it!
If you rely on random generation the danger is that all your platforms are all over to the left, or overlapping, or progress up might become impossible.
However, for a game jam, go for it! That might turn out to be part of the fun!
So, pretty late, the game is finished for some time now but here’s it! I’ve had some ‘complaints’ from people saying that the difficulty is unpredictable but it still turned out pretty well! You can play it at Drempal: Revamped by Mart Zielman, KittyCat81
1 Like
I can’t do it! Max score was 18. I love the blob with the umbrella though and your music fitted it perfectly. (LOL my ears were fine but thank you!)
EDIT Tried again - 23
I don’t understand the game.
What is the objective? How do you keep afloat? What does the shield do?
Max score I got was 5.
The umbrella protects you from meteorites. You have to reach the next rock platform quickly before the sea gets you. I am not sure why you only seem to get a couple of moves. Nor why it seems to suddenly stop moving, like it is out of power.
IDK, it was hard to work out. Shame it couldn’t start easy and get harder. I think my longest game was about eight seconds.
1 Like
Thanks, I managed a 25.
It got stuck though, just as you said. It wouldn’t jump anymore.
Not bad work for a solo project in a game jam.
I would still be “perfecting” things or more probably “abandoning” things lol.
1 Like
I know it’s a bit chunky, haha. For some reason the ‘shield’ would just block the blob at times, but you can move it with your mouse and it would move if you tilt it. Highest score I managed was about 120, lol. Also if you get the stars it gets you a multiplier!
1 Like