SOLVED [drag 'n drop] How to make pause menu appear in center of view

JimCity

Member
Hello friends,

I am learning how to make a top down adventure and am stuck on the pause menu. I have the game pausing with instances_deactivate_all and everything disappears which is fine. And the object controlling the pausing and menu creation isn't getting deactivated.

I've been trying to figure out how to use draw commands or create instances in the center of the current view as some rooms are large and the camera moves about. I was hoping to be able to return the numeral value of the viewport's position and store it as a variable then either create instance or draw rectangle at that position.

I tried using ""get view variable" in dnd and targeted them into variables but cant figure out how to use those variables for instance creating or drawing.

I also tried entering the built in variables "view_wport [0]" and "view_hport [0]" in the X and Y sections in "create instance and the object gets created at the viewport's bottom right corner but only at the viewports default location in the room editor. it doesn't get the updated coordinates after following obj_player.

Send Help.
 
Last edited:

Bryan112

Member
I usely store all this information at a seperated controller object.

Something like this:
global.SCREENWIDTH = camera_get_view_width(view_camera[0]);
global.SCREENHEIGHT = camera_get_view_width(view_camera[0]);

When you are drawing your pause menu just devide those varibles by 2, like:

draw_sprite(sprite, subimg, global.SCREENWITDH/2, global.SCREENHEIGHT/2);
 

JimCity

Member
I usely store all this information at a seperated controller object.

Something like this:
global.SCREENWIDTH = camera_get_view_width(view_camera[0]);
global.SCREENHEIGHT = camera_get_view_width(view_camera[0]);

When you are drawing your pause menu just devide those varibles by 2, like:

draw_sprite(sprite, subimg, global.SCREENWITDH/2, global.SCREENHEIGHT/2);
I usely store all this information at a seperated controller object.

Something like this:
global.SCREENWIDTH = camera_get_view_width(view_camera[0]);
global.SCREENHEIGHT = camera_get_view_width(view_camera[0]);

When you are drawing your pause menu just devide those varibles by 2, like:

draw_sprite(sprite, subimg, global.SCREENWITDH/2, global.SCREENHEIGHT/2);

I'm left with the same issue. The instance I'm creating appears inside the camera's original position from x0,y0, not where the camera has followed the player to.
 

Cameron

Member
You can use the draw_gui event and not worry about the coordinates in the room.
0 will == the top left of the screen for both x and y respectively.
display_get_gui_width() will be the far right of the screen and display_get_gui_height() will be the bottom of the screen.
Plus it'll take care of any depth issues as the gui is drawn over all regular draw events.
 

JimCity

Member
I deleted my last post because I found what was causing a problem.

This is where I'm at...

This took the surface screenshot so it looks like every object doesn't disappear during deactivate_all, or layer in my case.

camera_set_view_pos(view_camera[0], x - (view_wport[0]), y - (view_hport[0]));

And this took the current camera location and stored it into variables so I can spawn objects in the center of current view using xview and yview in "create instance" in drag and drop.

cam = view_get_camera(0);
xview = camera_get_view_x(cam);
yview = camera_get_view_y(cam);

My problem is they only work correctly in the first room. In every other room both the surface image and created instance aren't lining up right, a different section of the room is shown instead and the created instance isn't in the center of the view. I'm thinking it's to do with the different room sizes and or border sizes in the camera which follows the player. But I would of thought these codes apply to where ever the camera is currently positioned.
 
Last edited:

JimCity

Member
You can use the draw_gui event and not worry about the coordinates in the room.
0 will == the top left of the screen for both x and y respectively.
display_get_gui_width() will be the far right of the screen and display_get_gui_height() will be the bottom of the screen.
Plus it'll take care of any depth issues as the gui is drawn over all regular draw events.
I tried display_get_gui_width() / 2 and display_get_gui_height() / 2 and it didn't create the instance in the center of the current view, always towards the upper right of the room.
 

Cameron

Member
gui_draw_drag_and_drop.png

I don't use drag and drop so I had to start a project in one to make sure I wasn't leading you astray.

Make sure your event says draw_gui not just the draw event (notice the arrow).

use the display_get_gui_width()/2 and display_get_gui_height()/2 like have posted here. It will be center of the gui.

I center the text with the set text alignment drag and drop.
 

JimCity

Member
Weird, when I tried display_get_gui_width()/2 it didn't work. But I got it going with + instead. Had since been strugging to get an instance in the center of the view where ever in the room but finally got that too.
I was having some camera positioning problems when exiting pause state but one room was fine. tracked the only difference other than size was that in the first room the player is pasted in the room from the room editor, in all other rooms he spawns in depending where he last was. The room's cams were set to follow obj_player and when pause = true, deactivate layer which player is on. Then the following camera couldn't see the player and it displayed x0, y0 position over the paused image.

I created two new objects on a second instance layer separate from obj_player, one to handle camera and drawing and the second to represent a menu button; obj_cam and obj_button. I had everything in one before that also handels spawning but for now I'm seperating them into three. They are on layer "Instances_1," player and npcs are on "Instances."
I set all rooms to follow obj_cam and pasted it into the room, wherever. Moved the draw_gui event mentioned earlier into it and a create event that assigns the pause variable to false and a step event to make obj_cam move to the players position and stay on him when he moves. For that i used;
if(pause == false)
{
x = obj_player.x;
y = obj_player.y;
}

or jump to point player.x and player.y in dnd.
This obj_cam thing needs to be visible but have no sprite so you cant see the object but you can see the Draw events it now has.
Then in obj_cam's "key press "P"" event:Capture.PNGCapture.PNG
the /2 thing wouldn't work out with this code then I realized the xview and yview variables were getting x0 and y0 of the current view not the room because it was spawning the instance in the top right corner no matter where I stood. So like in the Draw GUI event I tried out the + and half of my viewport size or camera size (they both same size) and BAM! It worked.
I now have a sprite being drawn in center view that could cover the whole screen.
I can draw text and tell it where to show up.
And I can create an instance and control where it will appear.
All in the current view location wherever I stand.
That's good, I'm pleased with that.

Although I couldn't stop the instances from disappearing during pause. I used this code;

camera_set_view_pos(view_camera[0], x - (view_wport[0]), y - (view_hport[0]));

It worked but only when I used it by itself. When I had it active and in with the xview and yview variables pictured above it wouldn't work.
 

Attachments

Top