Movable mini map (Darkest Dungeon-style) using sprites and region_rect or other methods.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BennyDT

I’m trying to create a mini map similar to the darkest dungeon (2015) mini map using region rects and mouse position but I can’t seem to merge sprites together, or draw a sprite inside a sprites region rect.

My problem is drawing sprites on top of my region-rected sprite so that I can display rooms and paths to those rooms. If anyone has a better method, I am open for any idea that might work. Thank you.

how is my minimap
do you want something like this?

supper_raptor | 2020-04-29 07:40

Yeah, something like that.

BennyDT | 2020-05-01 20:34

:bust_in_silhouette: Reply From: BennyDT

I messed around with it and found an answer.

I, wildly over-exaggerated the issue and didn’t consider it a normal mini map with mouse movement but for the people who want to know what I did…

1 - Create a base image, preferably a grid but you do you. This will be the map.
2 - Put a sprite of whatever you want on the map in the same scene (We will duplicate it to create more elements on the map so hide it for now. We will show them in step 4)
3 - Duplicate the image to your hearts content using for loops. Also, add the duplicate sprites to their own node. We will use a for loop to get all that nodes children and move them as a unit. I will call this node $MapIcons for future reference.

4 - If your sprites position is outside the map, hide them. If they are inside, show them.

5 - Create a new input for left mouse button, (So that we can get is_action_just_pressed and is_action_pressed for the mouse button)

6 - Get mouse distance in between a click, I did this by setting an old_mouse position on-click and setting a new_click position using the is_action_just_pressed for the old_mouse and is_action_pressed for new_mouse. After you have those, you can probably find a way to use them but I used the code below to add them together and use them as one. I did this with the code below. It returns the amount you moved the mouse from the initial click to the drag of the mouse.

var old_click = Vector2(0,0)
var new_click = Vector2(0,0)

func mouse_position():
	# Remember to create the left mouse click input!! 
	if Input.is_action_just_pressed("left_mouse_button"):
		# Get the Initial Mouse Click Position
		old_click = get_global_mouse_position()
		# Return Nothing because we need to return something. 
		return Vector2(0,0)
	elif Input.is_action_pressed("left_mouse_button"):
		# Get the Current Mouse position while you hold the left mouse button
		new_click = get_global_mouse_position()
		# If distance is more than 0, return distance as a Vector2()
		if old_click.distance_to(new_click) != 0:
			var click_dis = Vector2(old_click.x - new_click.x, old_click.y - new_click.y)
			return click_dis
			return Vector2(0,0)
	# If nothing is pressed, reset everything.
		old_click = null
		new_click = null
		return Vector2(0,0)

7 - Use a for loop for all those children inside the $MapIcons and move their position (minus equals) -= mouse_position(). (Pluss makes it go reverse)

8 - Viola! Presto! We now have what I was looking for. Now you have the basic knowledge I have. Thank you for all the help!