SOLVED I'm having an issue with managing the cursor's sprite

ElCheTibo

Member
Hello everyone,

I'm making a game where you control a wizard who can either shoot something or heal himself.

I've made a sprite for the cursor. It contains 3 frames and the image_speed is already set to 0.
In the first frame, the sprite is white (neutral), in the second one it's red (attack) and in the last one it's green (heal).
What I'm trying to do is to change the sprite's frame based on whether the cursor is hovering the player or the ennemy.

I've putted the code in an object named oController, which is permananent and already placed on the room.

Here is the Create event of oController:
GML:
window_set_cursor(cr_none);
cursor_sprite = sCursor;
sCursor.image_speed = 0;
And here is the Step event:
GML:
if (collision_point(mouse_x, mouse_y, oEnemyParent, true, false)) {
    sCursor.image_index = 1;
}
else if (collision_point(mouse_x, mouse_y, oPlayer, true, false)) {
    sCursor.image_index = 2;
}
else {
    sCursor.image_index = 0;
}
The problem is: the cursor's sprite is being replaced (as expected) but the sprite keeps being seizure-worthy by displaying itself frame after frame at 60fps, and even if I move the move on the player or an ennemy, it changes nothing!

What am I doing wrong?
 

Nidoking

Member
sCursor is a sprite, correct? You can't use dot notation with a sprite. That has to be done with an instance. What you're probably doing is setting properties for an instance (or all instances) of the object that happens to share the same numeric index as that sprite.
 

ElCheTibo

Member
sCursor is a sprite, correct? You can't use dot notation with a sprite. That has to be done with an instance. What you're probably doing is setting properties for an instance (or all instances) of the object that happens to share the same numeric index as that sprite.
Oh I thought I could do that kind of thing...
So, can I fix this by making a "oCursor" object?
 

ElCheTibo

Member
Nvm, I fixed it by just making a sprite for each frame of sCursor and doing this:

GML:
if (collision_point(mouse_x, mouse_y, oEnemyParent, true, false)) {
    cursor_sprite = sCursorAtk; // red cursor
}
else if (collision_point(mouse_x, mouse_y, oPlayer, true, false)) {
    cursor_sprite = sCursorHeal; // green cursor
}
else {
    cursor_sprite = sCursor; // white cursor
}
Currently there is no way to use a sprite as a cursor natively that is at the same speed as the OS cursor. However, there is an extension that can help:
Oh thanks, I'll check it out! đź‘Ť
 
Top