It depends on how big is your map. I'm currently building world borders, using
RectangleShape2D as collision shape. It's not as expensive as you might think, the geometry of the shape is actually simple to check collision against (though I haven't really tested this yet), especially for a static body. I think it's possible to build limits/borders using
TileMap, but I have little experience using it.
If you want to try building borders the way I do, take a look at this structure:
The sprite defines visible border area, set the texture there, and make sure to import the texture with
Repeat flag in the import dock. The challenge here is to match the sprite with the actual shape's area. Here's the script that allows to texture the extents of the static body's rectangular shape as well as to change the actual size:
var size setget set_size
size = p_size
$sprite.region_rect = Rect2(Vector2(), size)
# CollisionShape2D is only used in editor!
# Use shape_owner to retrieve the actual shape.
shape_owner_get_shape(0, 0).extents = size / 2
Make sure to set
Region Enabled property for the sprite so that the pattern can repeat. If setting the size only resizes the region rect of the sprite and not the shape, you can try to set it on the next frame (I've had this issue when trying to initialize border sizes within a setter method of an
$border.call_deferred('set_size", Vector2(1000, 50)) # or ...
$border.set_deferred('size", Vector2(1000, 50)) # Godot 3.1
Most likely you'll also want to instance many borders and set different sizes for each. But if you try to change the extents of
RectangleShape2D, it will also resize the borders of all other instanced shapes! That's because the resources are created and loaded once, unlike other objects that can have many instances. To solve this, make sure to check
Local To Scene property so that the resource will be duplicated for each instanced border: