Tile Placement on Grid



I'm enjoying the course so far. I specially like the challenge of converting to Godot4, I think it helps me better understand the final product through the struggles.

Anyway, I'm trying to figure out how to adjust the level placement on screen. To me it seems to be a little to the left so to speak. Digging back through the code I really couldn't parse out where the Rect2 Locations mapped all that well with the eventual location. I wonder if it has to do with the tile size multiplied by the Rect2 points or something.

Any suggestions or help is appreciated,



  • Nathan Lovato replied

    The rooms' placement is handled in _get_random_room(), which calculates a random Rect2. But this isn't what I would use to center the dungeon on screen. Instead, you're better off using a Camera2D node to center the view on the dungeon.

    This is something we do with the function _setup_camera() in this lesson:

    func _setup_camera() -> void:
        camera.position = level.map_to_world(level_size / 2)
        var z := max(level_size.x, level_size.y) / 8
        camera.zoom = Vector2(z, z)

    This code centers the camera node on the level / the extents of the procedural generation grid. Normally, if you have this function and you're calling it in _ready(), your view should be centered on the generated level.

    If not, could you please zip and upload your project to a platform like Google Drive or We Transfer? We'll download your project and test it directly to tell you where the issue lies.