SOLVED Trying to get X and Y coordinates right for a point_in_rectangle

Hello there!

I'm trying to work my inventory system, and the inventory itself works fine, but I need a way to make the items individually selectable. So, from the help of some other people, I've decided to make a point_in_rectangle that finds out whether a small box on the right side of the items sprite display, and selects it accordingly. But, I'm just a tad stupid, and I can't get the x and y right. I'm asking for some help on finding the positions if you could please :)

thanks!

collision with pickupparent:
GML:
var key_pickup = keyboard_check_pressed(ord("E"))

if key_pickup {
    if other.object_index != noone {
        var key = other.object_index;
        var value = 1;

       if ds_map_exists(global.inventory,key) {
            value += ds_map_find_value(global.inventory,key); // Here we add the already existing number stored in the global.inventory[? key] to value
        }
        else {
            ds_list_add(global.inventoryItems,key)
        }
        ds_map_set(global.inventory,key,value); // Here we set the key in global.inventory to hold the updated value number
        instance_destroy(other)
    }
}
draw gui:
GML:
if shouldShowInventory { //shouldshowinventory defined in a key pressed 'tab' event
    draw_sprite(sinventory,0,0,0)
    var len = ds_list_size(global.inventoryItems);
    for (var i = 0; i < len; i++) {
        
        var key = ds_list_find_value(global.inventoryItems, i)
        var value = ds_map_find_value(global.inventory, key)
        
        var cam = camera_get_active()
        var camX = camera_get_view_x(cam)
        var camY = camera_get_view_y(cam)
        
        xMouse = device_mouse_x_to_gui(0)
        yMouse = device_mouse_y_to_gui(0)
        
        var GRID = 32
        draw_sprite_stretched(object_get_sprite(key), 0, camX + 32, (camY + i * GRID) + 64,48,48)
        draw_text(camX + 32 + GRID * 2, camY + i * GRID + 64,": "+string(value))
        
        if point_in_rectangle(xMouse,yMouse,0,(camY + i * GRID),(camY + i * GRID), (camY + i * GRID)) {
            
        }
        draw_rectangle(camX,(camY + i * GRID) + 64,(camY + i * GRID),(camY + i * GRID),false)
    }
}
my hopeless attempt at drawing the rectangle myself is just there ^^^

thanks again!
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
The first thing is to remove all the camera code you have in there... The GUI layer does NOT use cameras so those functions and variables are going to be causing you a lot of problems. The GUI layer uses an absolute coordinate system, so the top left is (0, 0) and the bottom right is (GUI width, GUI height), regardless of the position of the camera in a room. Removing the cam code should make it really easy for you to solve your problem now, as you have most of the code done already. :)
 
The first thing is to remove all the camera code you have in there... The GUI layer does NOT use cameras so those functions and variables are going to be causing you a lot of problems. The GUI layer uses an absolute coordinate system, so the top left is (0, 0) and the bottom right is (GUI width, GUI height), regardless of the position of the camera in a room. Removing the cam code should make it really easy for you to solve your problem now, as you have most of the code done already. :)
thank you very much! would I substitute camX and camY with just 0 or are there other numbers I might need?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
Well, you can substitute them for 0 if you want, but personally I'd just remove them entirely from the code... 0 + 32 = 32, so just use 32! That said, for things like that last draw call where you use camX on it's own you'd use 0 to start with and then adjust the value after testing if it's not appropriate.
 
Well, you can substitute them for 0 if you want, but personally I'd just remove them entirely from the code... 0 + 32 = 32, so just use 32! That said, for things like that last draw call where you use camX on it's own you'd use 0 to start with and then adjust the value after testing if it's not appropriate.
thanks so much!! :)
 
Top