Minimap tips, should I make a special camera? [SOLVED]


#1

Hi again! :smiley:

I need to create a minimap of my tilemap.
Can someone push me in the right direction and give me some tips?

I’m thinking about making a special camera that sees the entire tilemap and somehow streams the picture to a gui element. Is it how it’s done?

Thank you!


#2

I figured it out by modifying the render script, changing the view port and rendering the whole thing to that small viewport!


#3

I’m trying the accomplish the same thing. Any way you could post a code sample please?


#4

You need to have a custom render script. If you don’t already then copy the default.render_script and default.render from builtins and modify default.render so that it points to your copy of default.render_script instead of the one in builtins. Next change in game.project so that your copy is used. Add a print(“hello”) in the update() function to make sure it is running.

Next step is to modify the render script so that you do what @Ivan_Liljeqvist did. The part of the default render script that we are interested in looks like this (from the update function):

render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
render.set_view(self.view)

render.set_depth_mask(false)
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_STENCIL_TEST)
render.enable_state(render.STATE_BLEND)
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
render.disable_state(render.STATE_CULL_FACE)

-- default is stretch projection. copy from builtins and change for different projection
--
render.set_projection(stretch_projection(-1, 1))

render.draw(self.tile_pred)
render.draw(self.particle_pred)
render.draw_debug3d()

This portion of code starts by setting the viewport to cover the entire screen, then sets a view and projection plus some state setup and at the end it draws the graphics.

What you want to do is to do this twice, but with different viewports. Like this:

 render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
render.set_view(self.view)

render.set_depth_mask(false)
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_STENCIL_TEST)
render.enable_state(render.STATE_BLEND)
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
render.disable_state(render.STATE_CULL_FACE)

-- default is stretch projection. copy from builtins and change for different projection
--
render.set_projection(stretch_projection(-1, 1))

-- draw full screen first
render.draw(self.tile_pred)
render.draw(self.particle_pred)
render.draw_debug3d()

-- draw smaller version (15% of full size) at 10,10 
render.set_viewport(10, 10, render.get_window_width() * 0.15, render.get_window_height() * 0.15)
render.draw(self.tile_pred)
render.draw(self.particle_pred)
render.draw_debug3d()

For a very simple game this would be enough, but if you do a lot of complex rendering with expensive shaders it might be better to render to a render target once and then draw it twice (full screen and minimap). Although now that I think of it you probably want to draw the minimap with a simple shader if you use something more advanced when drawing fullscreen.


#5

That’s a good example, but as I understood - it’s just rendering the same, but resized scene.
I have similar task that I put to a long box ATM, but I would like to have simplified view for minimap, like in Diablo 2: https://vignette.wikia.nocookie.net/diablo/images/5/57/Cc06.jpg/revision/latest
Will it be normal solution to create programmatically another tilemap and attach it to the same camera (to make it fixed)? At least that’s the only thing that comes to my mind.


#6

Yes, it’s rendering the same thing twice. You could use two tilemaps and keep those in sync.