Hide/Show Platforms Loop

Godot Version

4.2.2

Question

I have couple platforms that aren’t visible on ready, I had this idea that when player jumps one platform appears and then player jumps again, platform_2 appears and the first one dissapears. I wanted to create a loop for handling that but can’t figure it out to work properly. I was also thinking about storing platforms in a dictionary or an array to make looping easier but I’m not sure how to go about this. If you got any tips I would be thankfull :slight_smile:

An array sounds good, if each platform knows it’s index and when the player jumps you could form something like this

var platforms: Array[Node2D] = []
var last_platform_jumped: int = -1

func jumped_from(index: int) -> void:
    if last_platform_jumped != -1:
        platforms[last_platform_jumped].visible = false
    platforms[index].visible = true
    last_platform_jumped = index
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.