Jump to content


Photo

mini map math


  • Please log in to reply
6 replies to this topic

#1 Darkadin

Darkadin

    GMC Member

  • GMC Member
  • 89 posts

Posted 10 February 2012 - 06:41 PM

so im trying to make a mini map for my game, i have a bunch objects in the room, im using it in my view and i have a feeling it has something to do with math. You would draw the original sprite where it is so it doesnt not draw it and you would draw a smaller version in the view corrisponding to where it is in the room, but i dont quite understand the math for this, any help? right now i have this for the map

if keyboard_check_direct(vk_tab)
{
draw_set_alpha(.6)
draw_set_color(c_green)
draw_rectangle(view_xview[0]+1,view_yview[0]+1,view_xview[0]+126,view_yview[0]+71,0)
}
  • 0

#2 drt_t1gg3r

drt_t1gg3r

    GMC Member

  • GMC Member
  • 3230 posts
  • Version:Unknown

Posted 10 February 2012 - 06:52 PM

just make another view in the room that takes up the zoomed width and height of the mini map then port it out to the actual size of the mini map then draw the view where you want to
  • 0

#3 Darkadin

Darkadin

    GMC Member

  • GMC Member
  • 89 posts

Posted 10 February 2012 - 06:56 PM

so using another view of the same view as the one im using, then port it to the top left of the first view i was using? im not too familar with the port functions how would i go about doing that?
  • 0

#4 Caracol

Caracol

    GMC Member

  • GMC Member
  • 153 posts
  • Version:GM8.1

Posted 10 February 2012 - 08:12 PM

You can probably handle a lot of it in the room view settings. Just create another view, set the view to the same width and length as the main view, and then for the "view port" stuff, set it to the size you want your minimap to be.

I haven't done a ton of minimap stuff either, but I want to say that adding a new view and zooming it way the heck out for your minimap might be a little cpu intensive. It's my understanding that comps have a harder time shrinking sprites than they do enlarging them. I'm not an expert, though, and depending on the size of your game it could be negligible.
  • 0

#5 mireazma

mireazma

    GMC Member

  • GMC Member
  • 282 posts

Posted 10 February 2012 - 09:16 PM

It would look like a tv screen while a mini map is not only a smaller version of the map but a lot simpler as well.
It has to do with math (like almost everything in game dev :smile: ). Now I regret I skipped math courses. Back to the topic:
There are numerous ways to do it. One would be this:
In the draw event of every mini-mappable object you draw 2 times.
Say you use 1024 x 1024 room, you got a 100 x 100 minimap in the top left of the screen and a car:
1024 / 100 = 10.24 is the divider;
draw_sprite_ext(sprite_index, image_index, x, y, 1, 1, direction, c_white, 1); // what GM generally does
draw_sprite(miniCar, image_index, x / 10.24, y / 10.24);
so the math involved in here is dividing normal scaled coords by how many times the minimap is smaller and adding the offset of minimap relative to the screen.
tada!

Edited by mireazma, 10 February 2012 - 09:26 PM.

  • 0

#6 Darkadin

Darkadin

    GMC Member

  • GMC Member
  • 89 posts

Posted 10 February 2012 - 11:53 PM

i tried your math in my coding and it didnt work, not sure why, maybe because im using views heres the code i used

draw_sprite(enemy,1,x,y)
draw_sprite(enemy,1,view_xview/42.6,view_yview/48)

my room size is 6400 4800, and my mini map is 150 100
soo, 6400/150 is about 42, and 4800/100 is 48
i tried using it without the vIew_xview and view_yview and just using x and y but that didnt work either not sure what i did wrong?
  • 0

#7 mireazma

mireazma

    GMC Member

  • GMC Member
  • 282 posts

Posted 11 February 2012 - 10:01 AM

EDIT:
draw_sprite_ext(sprite_index, image_index, x, y, 1, 1, direction, c_white, 1);
draw_sprite_ext(sprite_index, image_index, view_xview + x/42.6, view_yview + y/40, 1/10, 1/10, direction, c_blue, 1);
view_xview and view_yview are always at 0, 0 coords relative to screen so you have to offset the coords of the mini object to these vars.

Edited by mireazma, 11 February 2012 - 10:48 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users