• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Left Mouse Released Event Unresponsive

B

Basic_Pete

Guest
I was copying a tutorial on how to make a simple system of dragging individual cards onto a deck of cards. I've copied the code exactly and know it's right. It seems that the left mouse pressed and released events are just unresponsive. Most the time I click on a card and it stays following the mouse no matter what I do, only thing that fixes it is clicking on a different card. However under specific circumstances that I haven't been able to work out the card will either go into the deck or stay where I left it.

Also the tutorial was in GMS 1.4 and I'm using GMS 2, don't know if that affects it.

I know this is vague but any help would be great.
 

Nidoking

Member
How are you determining that the events aren't happening? Is it possible that they're happening, but the logic you're using is faulty?
 

tetris_mess

Member
Have you used show_debug_message at the beginning of the step event to check what's going on when you simply press and release the left mouse button? There are a lot of keyboard and mouse events you can research in the documentation. If you put show_debug_message at the beginning of the step event and see nothing happening still, that's a more complicated situation.
 

samspade

Member
Post the code you have and the events that code is in. Without more it is just a guess. Having to guess, I would guess it is an issue with either the sprite's mask or the use of global/non-global mouse events.

There are differences between 1.4 and 2 but not many in that area (e.g. mouse functions and events) so it should transfer pretty straightforwardly.
 
B

Basic_Pete

Guest
Post the code you have and the events that code is in. Without more it is just a guess. Having to guess, I would guess it is an issue with either the sprite's mask or the use of global/non-global mouse events.

There are differences between 1.4 and 2 but not many in that area (e.g. mouse functions and events) so it should transfer pretty straightforwardly.
This is what I have as an End Step for when a card is selected:
Code:
if (global.card != noone) {
    
    with (global.card) {
        x = mouse_x;
        y = mouse_y;
        
    }
}
When the left mouse is pressed:
Code:
global.card = id;
depth = -1;
This is for when the left mouse is released:
Code:
if (position_meeting(mouse_x, mouse_y, obj_deck)) {
    
    with(obj_deck) {
        ds_stack_push(deck, global.card.sprite_index);
    }
    with(global.card) {
        instance_destroy();
    } 
}
global.card = noone;
depth = 0;

And this is when the mouse clicks on the deck again:
Code:
if (ds_stack_size(deck) > 0) {
    
    var top_card = instance_create_depth(x, y, 1, obj_card)
    var card_sprite = ds_stack_pop(deck);
    top_card.sprite_index = card_sprite;
    global.card = top_card;

}
 
I'm shooting from the hip here so back up your project first.

Try making this your "Step" event instead of "End Step."
Code:
if (global.card != noone) {
 
    with (global.card) {
        x = mouse_x;
        y = mouse_y;
     
    }
}
Add this to your create event.
Code:
pressed = false;
Add a line your "Left Pressed" event.
Code:
global.card = id;
depth = -1;

pressed = true;
Turn your "Left Released" event into "Global Left Mouse Released" and modify it like this:
Code:
if pressed {
    if (position_meeting(mouse_x, mouse_y, obj_deck)) {
 
        with(obj_deck) {
            ds_stack_push(deck, global.card.sprite_index);
        }
        with(global.card) {
            instance_destroy();
        }
    }
    global.card = noone;
    depth = 0;
    pressed = false;
}
I hope this will fix your problem, but I sort of doubt it because I'm not entirely sure what the problem is.

I worked on a card example a few weeks ago. If the above doesn't work, maybe take a look at that?

 

Nidoking

Member
Is the origin of the card sprites in the center? If it's at a corner, then it would be easy for the mouse not to be on the card when the button is released, so it wouldn't activate the Released event. This is why I asked how you know the event is firing, and you didn't answer.
 

samspade

Member
Given that code I'd say my guess is still the most likely answer. If you use a mouse pressed/released etc. event (e.g. not the global ones) then it only fires if the mouse x/y is colliding with the instance.

Since you update the instance's x and y to be the mouse's x and y this would work in most circumstances but if your mask was off (as Nidoking pointed out) then the mouse may not be colliding with the instance's mask.

One solution would be to switch to a global left mouse release. Another would be to double check your instance's mask and origin point. An instance's x and y is its sprite's origin point (if there is one) so if your origin point is either outside of or on the edge of the mask it would be easy for the mouse to be off it (again as Nidoking pointed out).
 
B

Basic_Pete

Guest
Is the origin of the card sprites in the center? If it's at a corner, then it would be easy for the mouse not to be on the card when the button is released, so it wouldn't activate the Released event. This is why I asked how you know the event is firing, and you didn't answer.
Thanks, this seems to work. Really appreciate it.
 
Top