0 votes

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.

asked Apr 29 in Projects by BennyDT (18 points)

how is my minimap https://youtu.be/7Hd66AzfdXo
do you want something like this?

Yeah, something like that.

1 Answer

0 votes

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 isactionjustpressed and isaction_pressed for the mouse button)

6 - Get mouse distance in between a click, I did this by setting an oldmouse position on-click and setting a newclick position using the isactionjustpressed for the oldmouse and isactionpressed 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!

answered May 2 by BennyDT (18 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.