Help with map functionality

Godot Version



Hello! So I am triyng to make a map game, and I need help with map functionality. Hod do I do map with countries, when clicked opens menu that is different for all nations?

I really appreciate any help as I am realky passionate about this project.
Thank you.

The best way I can think of is to use an Area2D made up of CollisionPolygon2D children for each defined region of the map.

CollisionPolygon2D allows you to draw a collision shape.

Example Scene Tree:

- UnitedStatesMap: Sprite2D
  - Area2D
    - Washington: CollisionPolygon2D
    - Oregon: CollisionPolygon2D
    - California: CollisionPolygon2D
    - ...

We use an Area2D which enables input event detection through its collision shapes.

extends Area2D

func _input_event(viewport: Viewport, event: InputEvent, shape_idx: int) -> void:
	if event is InputEventMouseButton and event.pressed:
		var oid = shape_find_owner(shape_idx)
		var own = shape_owner_get_owner(oid)

The above code will print “Washington”, “Oregon”, and “California” when their associated shapes are clicked.

1 Like

Thank you.