GML Changing cursor sprite back to normal when on a specific object?

B

BenSunhoof

Guest
Hey there. I have a piece of code that changes the cursor sprite to a custom one and makes it green whenever it hovers over something clickable:
Code:
var inst;
inst = instance_position(mouse_x,mouse_y,all)
if inst != noone
cursor_sprite = spr_cursor_slct
else
cursor_sprite = spr_cursor;
if position_meeting(mouse_x,mouse_y,obj_edge)
cursor_sprite = spr_cursor;
However, as you can see, there's an obj_edge that works as bounds as to where the player can go, here's the piece of code in obj_player's Step Event that creates collision:
Code:
//Simple collision with bg
if !position_meeting(x,y-1,obj_edge)
{
    y += 3
    instance_destroy(obj_click);
    speed = 0;
}
This is how it works: my player moves towards the position of obj_click that's created when LMB is pressed. Whenever you click outside the floor panels, the player moves there, but when they hit the bbox top of obj_edge (which is invisible and covers the entire floor), they stop and obj_click gets destroyed. But that's just for context of what obj_edge does.

Anyway, that's besides the point. My main issue is that I don't want the cursor sprite to change colour when it's over obj_edge. The code I wrote doesn't seem to work. Any suggestions please?
(Also, as I was taking a screenshot, I noticed that the cursor turns green whenever I click, my idea is that it also detects obj_click for one frame)
For the record, yes, I fully understand my design and code are incredibly flawed.
 
Last edited by a moderator:
You can make a parent object called "oClickableParent" and make all the object that can be clicked inherit from it.

var inst;
inst = instance_position(mouse_x,mouse_y, oClickableParent) // Now you're checking only whether the mouse is over a clickable object
if (inst != noone) {
cursor_sprite = spr_cursor_slct
} else {
cursor_sprite = spr_cursor;
}

Hope that works.
 
B

BenSunhoof

Guest
You can make a parent object called "oClickableParent" and make all the object that can be clicked inherit from it.

var inst;
inst = instance_position(mouse_x,mouse_y, oClickableParent) // Now you're checking only whether the mouse is over a clickable object
if (inst != noone) {
cursor_sprite = spr_cursor_slct
} else {
cursor_sprite = spr_cursor;
}

Hope that works.
I think that worked, yeah, thank you. But what if I want to put something else in the object's Step event? Do I just copy the code from ClickableParent and paste it there?
 
All the events are automatically inherited from the parent object, but if you want to add additional code for your child object, you have to call event_inherited() , otherwise you will overwrite the parent's event code.


Code:
// STEP EVENT
// inherit step event from the parent object
event_inherited();

/// Put the rest of your additional child's code
...
..
..
 
B

BenSunhoof

Guest
All the events are automatically inherited from the parent object, but if you want to add additional code for your child object, you have to call event_inherited() , otherwise you will overwrite the parent's event code.


Code:
// STEP EVENT
// inherit step event from the parent object
event_inherited();

/// Put the rest of your additional child's code
...
..
..
Okay, thanks a lot!
 
Top