ThePlayerEden
Member
So I have this simple inventory code that I tweaked a bit from a Youtube tutorial, anyways, the inventory mechanics works fine in my starting room. The problem is when I leave the room, the items in my inventory go off-camera in the corner of said room, instead of the corner of the player's view.
I've tried multiple different ways of writing the code, but I'm no expert and honestly not too sure what is going on and how to fix it.
Here's a copy of the code:
I've tried multiple different ways of writing the code, but I'm no expert and honestly not too sure what is going on and how to fix it.
Here's a copy of the code:
GML:
//Code of "obj_item_manager"
***CREATE***
//....
//create the inventory
inv = array_create(0);
inv_max = 5;
selected_item = -1;
//drawing and mouse positions
sep = 6;
screen_bord_x = camera_get_view_x(view_camera[0]) + 4;
screen_bord_y = camera_get_view_y(view_camera[0]) + 8;
***DRAW***
for (var i = 0; i < array_length(inv); i++)
{
var _xx = screen_bord_x;
var _yy = screen_bord_y;
var _sep = sep;
var _col = c_white;
//icon
draw_sprite_stretched(inv[i].sprite, 0, _xx, _yy + 6*i, 4.5, 5);
//get "selected" color
if selected_item == i {_col = c_yellow;};
draw_set_color(_col);
//name
draw_text_transformed(_xx + 6, _yy + _sep*i,inv[i].name, .5, .5, 0);
//description
if selected_item == i
{
draw_text_ext_transformed(_xx + 6, _yy + _sep*array_length(inv), inv[i].description, 8, 80, .5, .5, 0);
}
//inventory space
draw_text_transformed_color(_xx + 1.6, _yy + _sep*array_length(inv), "/5", .25, .25, 0, c_white, c_white, c_white, c_white, 1);
draw_text_transformed_color(_xx + .5, _yy + _sep*array_length(inv), array_length(inv), .25, .25, 0, c_white, c_white, c_white, c_white, 1);
//reset color to white
draw_set_color(c_white);
}
***STEP***
//get selected item
selected_item = -1;
for (var i = 0; i < array_length(inv); i++)
{
var _xx = screen_bord_x;
var _yy = screen_bord_y + sep*i;
if mouse_x > _xx && mouse_x < _xx + 10 && mouse_y > _yy && mouse_y < _yy + 10
{
selected_item = i;
}
}
if selected_item != -1
{
//use an item
if mouse_check_button_pressed(mb_left)
{
inv[selected_item].effect();
}
//drop the item
if mouse_check_button_pressed(mb_right) && inv[selected_item].can_drop == true
{
//get rid of the item
array_delete(inv, selected_item, 1);
}
}
//code of the item/s
***CREATE***
item = global.item_list.potato;
***STEP***
sprite_index = item.sprite;
if place_meeting(x, y, obj_player)
{
if item_add(item) == true
{
instance_destroy();
}
}