changing cursor to different objects

I am trying to create a Room Escape Game and am having trouble with the mouse. I want to be able to have the user click on an item in the room (wrench_obj), and have it stored in the inventory off to the side (as wrench_inv). I then want the player to later be able to click the inventory item and use it to interact with something in the environment (pipe_obj). My desire is to have the cursor icon turn into the inventory image after it is selected (LMB), and remain that way until it is either used or intentionally changed back to the cursor.

I achieved this effect in GM 8.1 but had to use 3 different objects (wrench_obj, wrench_inv, and wrench_cursor). This seems incredibly redundant since the _inv and _cursor images were identical. I also had to code every single object as I hadn't had a firm understanding of parenting at the time.

I'm new to GMS2 and haven't used any GM product in about 3 years. I've figured out how to change the cursor to the inventory item, but it will not follow the mouse. OR... The cursor sprite and the inventory item both follow the mouse, but immediately after the original object (wrench_obj) is clicked... this is before it even shows in the inventory.

I poured over articles on this and feel I am close. I'm just not making it work. Any thoughts?

TL;DR: How do I make the cursor turn into a different object when clicked? Can I parent this to apply to all objects of this type?

Thanks.
 

Rob

Member
There are plenty of ways to do it, here is one:

Have a single sprite that contains every item (obviously you cant do this if your sprites are animated so you'd need an extra step of making an array and saving the sprite names into it).

Make an enumerator that lists the items. The order of the enumerator should match the order of the images in the single sprite that contains all of the item sprites (or array if you have animated sprites);

When you "pickup" an item, it should know which item it is, so if you have an apple, it should have a variable called item_type set to e_items.apple. (e_items.apple is the enumerator).

Have a variable called mouse_sprite_index, and set it to -1 when you don't want to draw anything over the mouse. When you pick something up or want to display something in the mouse, set mouse_sprite_index to the items enumerator eg:


GML:
//Step event of whatever object has the variable "mouse_sprite_index"

//Check for a mouse click
if mouse_check_button_pressed(mb_left){
    //check to see if there's an item where the mouse is clicked
    var item = collision_point(mouse_x, mouse_y, obj_item); //I like to use one object for ALL items!
   
    if (item != noone){
        //There's an item under the mouse so set the mouse sprite to it
        mouse_sprite_index = item.item_type
    }
}
Code:
//draw event of the same object as before
if (mouse_sprite_index != -1){
    draw_sprite(spr_all_items, mouse_sprite_index, mouse_x, mouse_y);
}
I'm leaving plenty of stuff out and it may be easy or hard for you to fill those things in depending on how much GML you know but you can always ask if you get stuck.
 
Rob,
Thank you for your help. I've tried it and I just couldn't quite figure it out. You said there were several ways of making it work though. I think I have stumbled across one.

On LMB Release (for each inventory object):
cursor_sprite=whatever_sp
window_set_cursor(cr_none)

Seems to be working so far.
I appreciate your response, and offer to help.
Thank you
 
Top