0 votes

I want to make a MiniMap, and I have a idea, but please write if this idea is a bad attempt.

So this is my idea:

I have a Frame for my MiniMap and inside of the Frame, I want to show the MiniMap. I made the whole Map as a png File and now I want to show just a small part of this map inside of my Frame and then, when the Player moves, I want to move my map as well, but I want that only the part of the map inside the Frame is visible. Is there a way to do that or is this a bad attempt for a MiniMap?

Thanks for answers and ask if there are ambiguities.

PS: Sorry for bad English and the word ambiguities is from the google translator...

in Engine by (330 points)

1 Answer

0 votes
Best answer

I am using TextureRect for minimap and i am using shader to move map with my player.
Create TextureRect and check expand and set stretch mode to tile. Then add shader

Shader code

shader_type canvas_item;
uniform vec2 pos;

void fragment()
    COLOR = texture(TEXTURE, UV + pos);


var worldsize = Vector2() #your world size

func moveMapWithPlayer():
    #half resolution , used to keep player centered in minimap
    var half_res = get_viewport().size / 2  
    var pos = player.position - half_res

    pos.x = clamp(pos.x,0, worldsize.x)
    pos.y = clamp(pos.y,0, worldsize.y)
    material.set_shader_param("pos",pos / worldsize)

func _process():
by (731 points)
selected by

Ok, thank you!

But the problem was less that my map is empty and more that you can see the rest of the map outside the frame

I will make another question on this later

Its my function to generate minimap of a level.

func captureMap():
    #minimap to actual map ratio
    var ratio = 8   

    #64 is tile size
    var size = $TileMap.get_used_rect().size * Vector2(64,64)
    OS.window_size = size / Vector2(ratio,ratio)
    var max_xy = min(size.x,size.y)
    var ratio
    if max_xy == size.x:
        ratio = OS.window_size.x / max_xy
        ratio = OS.window_size.y / max_xy

    self.scale = Vector2(ratio,ratio)

    yield(get_tree(), "idle_frame")
    yield(get_tree(), "idle_frame")
    yield(get_tree(), "idle_frame")
    yield(get_tree(), "idle_frame")
    # Retrieve the captured Image using get_data()
    var img = get_viewport().get_texture().get_data()
    # Flip on the y axis
    # You can also set "V Flip" to true if not on the Root Viewport
    # Convert Image to ImageTexture

and btw

worldsize = $TileMap.get_used_rect().size * Vector2(64,64)

64 is default tile size

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.