• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows When an instance is created, how do I make it so that it is created in the center of my viewport?

S

sma

Guest
I have a viewport with the size of 1024x768, and an object with this code.


GML:
//CREATE EVENT
menu_x = x;
menu_y = y;
button_h = 60;



// buttons
button[0] = "Stats";
button[1] = "Inventory";
button[2] = "Close";
buttons = array_length_1d(button);

menu_index = 0;
last_selected = 0;


//this is what should define its starting position
x = camera_get_view_x(view_camera[0])+500   
y = camera_get_view_y(view_camera[0])+500
I don't understand why this doesn't work, as when the instance is created, it's position is not in the center of the viewport
 
If you want the center of 1024x768, shouldn't that be (512, 384)?

Code:
//this is what should define its starting position
x = camera_get_view_x(view_camera[0])+512  
y = camera_get_view_y(view_camera[0])+384
 
Top