|
|
|
|
Reply From: |
supper_raptor |
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);
}
code
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
#clamp
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():
moveMapWithPlayer()
I add the second code to the TextureRect and the first code to the shader of the TextureRect, right? Because I got a error, which says that the variable pos isnt declared.
What did I wrong?
Godot_Starter | 2020-05-22 07:32
sorry it’s
var pos = player.position - half_res
and u have to set worldsize
supper_raptor | 2020-05-22 07:38
I set the worldsize to 128,128 and I wrote 0,0 as the player.position, in order to test it.
And does it matters where the minimap is located? Because it still happens nothing.
Godot_Starter | 2020-05-22 07:53
I can still see the rest of the MiniMap outside the Frame
Godot_Starter | 2020-05-22 07:53
worldsize is in pixels 128x128 is very small
supper_raptor | 2020-05-22 07:59
ok I increesd it to 12800, 12800 (my world isnt finished so its just a number) and this is, how it looks in the editor right now:
Godot_Starter | 2020-05-22 08:05
Obviously, you cant open the image… In fact, it still doesnt work and does the start position of the Player and the Minimap maters?
Godot_Starter | 2020-05-22 08:07
i cant view ur image
supper_raptor | 2020-05-22 08:09
have u assigned texture in textureRect?
supper_raptor | 2020-05-22 08:10
Can I add a .tscn to a comment? Because then I would be able to send you my scene
Godot_Starter | 2020-05-22 08:16
you cannot send .tscn directly , you need to host it somewhere and send link in comment.
Upload here http://s000.tinyupload.com/ and paste the link in comment
supper_raptor | 2020-05-22 08:20
It is a 7zip file, I hope you can deal with it. If not write me. The important thing is not to move the MiniMap, the important thing is that I cant see the MiniMap outside of the Frame. Thats why I made a fix Node2d as a Player, in order to test it.
Godot_Starter | 2020-05-22 08:36
To create minimap.png
like i have done , you need to-
1.)Make a level
2.)capture screen shot
use this image as ur minimap
supper_raptor | 2020-05-22 08:56
Ok, thank you!
Godot_Starter | 2020-05-22 09:16
But the problem was less that my map is empty and more that you can see the rest of the map outside the frame
Godot_Starter | 2020-05-22 09:27
I will make another question on this later
Godot_Starter | 2020-05-22 09:28
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
else:
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
img.flip_y()
# Convert Image to ImageTexture
img.save_png("res://minimap.png")
supper_raptor | 2020-05-22 09:30
and btw
worldsize = $TileMap.get_used_rect().size * Vector2(64,64)
64 is default tile size
supper_raptor | 2020-05-22 09:32