GMS 2 Drawing Inventory to Camera

S

Spencer S

Guest
I'm trying to center an inventory sprite onto the camera position, so that the inventory stays on the gui. I don't want to draw the inventory to the gui; I want to draw the inventory to coordinates that are determined every step of the game.

Here is my inventory's create event:
Code:
topLeftOfCameraXAxis = camera_get_view_x(view_camera[0]);
topLeftOfCameraYAxis = camera_get_view_y(view_camera[0]);
middleOfCameraXAxis = camera_get_view_width(view_camera[0]) * 0.5;
middleOfCameraYAxis = camera_get_view_height(view_camera[0]) * 0.5;
inventoryBackgroundHeight = sprite_get_width(spr_inventory_background);
inventoryBackgroundWidth = sprite_get_height(spr_inventory_background);
Here is my inventory's step event:
Code:
if obj_player.key_menu {
    draw_sprite(spr_inventory_background, 0, ((topLeftOfCameraXAxis + middleOfCameraXAxis) - (inventoryBackgroundWidth / 2)), ((topLeftOfCameraYAxis + middleOfCameraYAxis) - (inventoryBackgroundHeight / 2)));
}
And here is my inventory's end step event:
Code:
topLeftOfCameraXAxis = camera_get_view_x(view_camera[0]);
topLeftOfCameraYAxis = camera_get_view_y(view_camera[0]);
middleOfCameraXAxis = camera_get_view_width(view_camera[0]) * 0.5;
middleOfCameraYAxis = camera_get_view_height(view_camera[0]) * 0.5;
I'm trying to follow this tutorial https://forum.yoyogames.com/index.php?threads/guide-meet-the-new-camera-system.12269/ and use the code for my own purposes, but as of right now, the inventory isn't showing up at all. Anything wrong with my code?
 
S

Spencer S

Guest
Placing the function inside a Draw event or Draw GUI event didn't work.
 
B

Box Face Friend

Guest
Hi,
I haven't drawn an inventory to the screen but I have drawn a pause screen and item shop. I used the draw_sprite function in the draw event, similar to yours. I also set a depth in the creation code of a minus number to make sure it was shown above everything else.

Is the inventory object created when pressing a key? Or is it already in the room?
 
Top