• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Drawing interfaces with GUI?

I'm trying to create a menu/interface, which is docked at the bottom of the screen and displays sprites all of the buildings the player can create, along with a "purchase" button next to each of the sprites. The player clicks the button to open up the interface, which pops up, but the buttons are only clickable when the mouse is over a certain position? The map moves with viewports when the cursor is near the edge of the screen, so the objects are not always in the same position.

Code that displays the objects on screen:
Code:
var posX = 500;
obj1 = instance_create_layer(100, posX, "GUI", obj_bm_placeholder);
purchase = instance_create_layer(100, posX+30, "GUI", obj_bm_purchase);
obj1.itemID = "palace";

obj2 = instance_create_layer(210, posX, "GUI", obj_bm_placeholder);
purchase = instance_create_layer(210, posX+30, "GUI", obj_bm_purchase);
obj2.itemID = "mineshaft";

obj3 = instance_create_layer(320, posX, "GUI", obj_bm_placeholder);
purchase = instance_create_layer(320, posX+30, "GUI", obj_bm_purchase);
obj3.itemID = "watersupply";

Draw GUI event:
Code:
var spritename = asset_get_index("spr_construction_" + string(itemID));
draw_sprite(spritename, 0, x, y);
any advice would be appreciated.
 

Binsk

Member
To expand on what @TheouAegis said, because the GUI follows the camera you'll need to convert coordinates at some point so they match up.

1) If you use the EVENT mouse_click or whatever, you'll need to constantly move the object positions so that they match up to the view so that the clicking is in the right spot.

2) If you do your OWN click detection for your objects you can either 1) Convert the object positions to the camera location (similar to (1)) or convert the mouse coordinates away from camera location. If you do this you can either subtract the view location from your mouse_x/y coordinates or you can instead use window_get_mouse_x/y functions instead.
 
Top