Legacy GM (Slightly Solved) Minimap - Working [Another Issue]

S

Sypher714

Guest
Final Result for NON ROTATING Minimap.
You may use the code if you like, located under this screenshot. Otherwise if you are here to help out on my 2nd problem start scrolling down.


Code if anyone is interested. 2 Objects required, written in BOLD. This is just my setup, I am not sure if it is a correct method but it works fine for me.
NOTICE - the appearing icons in the radar isn't included in this code.

par_minimap
Assign objects you want to be seen in Minimap to this parent. Or if your object(s) already have a parent assigned, assign the parent to this parent.

obj_minimap
Code:
//Create

/// Init
oSurface = -1;


//Step

//Your Values can be optional. This is what i am currently using.
if (!surface_exists(oSurface))
{
    oSurface = surface_create(400, 400);
}
surface_set_target(oSurface);
draw_clear(c_white);

//This part is optional
draw_set_alpha(0.7);
draw_background_tiled(bg, 0, 0);
draw_set_alpha(1);

//Get objects for population on map
var numObjects = instance_number(par_minimap)

for ( var i = 0; i < numObjects; i++ )
{
    var obj = instance_find( par_minimap, i );
    var _px = obj_player.x
    var _py = obj_player.y
    with(obj)
    {
        draw_sprite( sprite_index, 1, x+200 - _px, y+200 - _py);
    }
}
surface_reset_target();



//Draw GUI

if (surface_exists(oSurface))
{
    //Your Values can be optional. This is what i am currently using.
    draw_surface_stretched( oSurface, 0, 60, 200, 200 );

    var old = draw_get_color();

    // Get underlay color.
    draw_set_color(c_white);

    //Your Values can be optional. This is what i am currently using.
    draw_rectangle( 0, 60, 200+0, 200+60, true);

    draw_set_color(old);
}
 
Last edited by a moderator:
is your minimap surface exactly the same size as your room? I'm trying to figure out how you are translating from world to map coordinates.

Anyway, I think the solution is just to subtract the player's position from each thing's x and y coordinates when drawing onto the map surface. You're not supopsed to draw anything outside of the draw events, by the way.
 
S

Sypher714

Guest
is your minimap surface exactly the same size as your room? I'm trying to figure out how you are translating from world to map coordinates.

Anyway, I think the solution is just to subtract the player's position from each thing's x and y coordinates when drawing onto the map surface. You're not supopsed to draw anything outside of the draw events, by the way.
No, the room size differs from Minimap size. Oh so I should set it in Draw Event correct? And where would I put or start "subtract the players position" ?

This is my first time trying to do a minimap.
 
Well first of all, this isn't how I'd make a minimap, so I'm just going to assume your system is working correctly as it is.

Code:
        var _px = obj_player.x;
        var _py = obj_player.y;
        with(obj){

        draw_sprite( sprite_index, 0, x - _px, y - _py);
    }
Above... first get the player instance's position (make sure it exists first), then subtract its position from the position of each thing you draw on the map.
 
S

Sypher714

Guest
Solved. Close!
 
Last edited by a moderator:
S

Sypher714

Guest
I got my method working. I just did draw_sprite( sprite_index, 1, x+64 - _px, y+64 - _py);

Thanks for your help though man! Really appreciate it
 

RangerX

Member
Why do you erase you post?
When you find a solution you simply tag it as solved and you leave it there. This way, when other people are searching the forum they can actually find something.
 
S

Sypher714

Guest
One thing I would like to add is, how would I have the minimap rotate? Like have it rotate with the player direction?

I tried obj_player.x + direction and the map just moves and snaps back in a weird way, so I am going to throw that out, that is not the correct way.
 
Last edited by a moderator:

lolslayer

Member
I would use something like this when drawing the sprite on the surface:

var len = point_distance(x,y,obj_player.x,obj_player.y);
var dir = point_direction(x,y,obj_player.x,obj_player.y)+screen_rotation;
draw_sprite(sprite_inded,1,lengthdir_x(len,dir)+200 - _px ,lengthdir_y(len,dir)+200 - _py);
 
if you were using a projection to draw your map all you'd have to do is change to angle of the projection. Another thing you could do is use the rotate z d3d transform. The alternative would be to rotate the location of every single thing drawn on the minimap on an individual basis (wasteful if done in GML).
 
S

Sypher714

Guest
I would use something like this when drawing the sprite on the surface:

var len = point_distance(x,y,obj_player.x,obj_player.y);
var dir = point_direction(x,y,obj_player.x,obj_player.y)+screen_rotation;
draw_sprite(sprite_inded,1,lengthdir_x(len,dir)+200 - _px ,lengthdir_y(len,dir)+200 - _py);
Would +screen_rotation be assigned to obj_player.direction?

I tried the following
Code:
    var obj = instance_find( par_minimap, i );
    var _px = obj_player.x
    var _py = obj_player.y
    var screen_rotation = obj_player.direction
    //with(obj)
    //{
        //draw_sprite( sprite_index, 1, x+200 - _px, y+200 - _py);
    //}
    var len = point_distance(x,y,obj_player.x,obj_player.y);
    var dir = point_direction(x,y,obj_player.x,obj_player.y)+screen_rotation;
    with(obj)
    {
        draw_sprite_ext(sprite_index,1,lengthdir_x(len,dir)+200 - _px ,lengthdir_y(len,dir)+200 - _py,1,1,screen_rotation,c_white,1);
    }
The sprites do rotate, but the player is not drawn the the center anymore and the map does not move anymore. Screenshot soon of result.
 
Last edited by a moderator:
I've update my minimap example to make the minimap rotate along with the current view angle. You should take another look at it, becuase it is unnecessary to calculate the position of everything on the map individually. It would really save cpu to just set a projection for the minimap surface to use.

minimap.gmz 11KB
https://app.box.com/s/r56dnoad6zx9x2c4wz8zxlydgolvxk4e

Controls are...
A,D rotate player (and view)
arrow keys move player (and view).
 
Last edited:
Top