Mouse down staying active outside game window

I read the forum posts about the mouse clicks being outside of game window. I have created a fruit ninja style game and when the player swipes to cut the fruit, there is a possibility of the mouse going outside of the game screen. As a result, the following is happening.

  • You press and hold the left button to swipe
  • You go out of the screen with the left button still pressed
  • You release the left button outside of the screen, BUT the game is not aware of this event.
  • You put back your mouse in the game, and you now have the button released but it is still considered as pressed by your game.

The swipe effect stays on and I don’t have any mouse buttons pressed.
Any ideas how to trigger a mouse release if the mouse is outside of the game screen? I tried adding conditions where I checked to see if the position of the mouse was outside the scene area but I couldn’t find any action to do a mouse pressed release.

I believe this is due to the game renderer (and most in general) only being able to understand actions when it is the focus.

Once you’re outside of the window it can no longer detect that, and not take any actions based off that, so it is doing what it last knew you were doing with it.

You might try using the “Window is focused” Condition as a requirement for your actions? That way if the window is not focused (You’re outside of the window clicking), none of the “Mouse button is down” actions will count.

1 Like

I added the Window Focused condition. It will remove the mouse button is down action only if I click outside of the window. It does not remove the mouse button is down action if I do not click outside of the window. For example, I can click inside the window, drag to the outside of the window and release the mouse button. Then move the mouse back into the scene window without clicking and it is still recognizing the mouse down action. Any other suggestions?

Hello! This is maybe improvisation, but can you test out making sprite to cover your whole screen, make it invisible, and do events when mouse cursor is not in collision with that sprite, disable action/commands for your game. This also applies using variables that will check current mouse cursor position. Let me know if this idea kinda works, because sometimes easier concept to do, works better than extensions and scripting :smiley:
Also if you plan to do multiple screen resolutions, resize sprite for every single one. Do presets.

I like monochroma380’s idea, but I think the problem is going to be that the cursor stops being tracked at the boundaries of the screen. So in theory the collision will always be happening.

So long as you’re not expecting edge to edge control, however, you could make it work by having it check that the mouse cursor is more than 2 pixels away from the edge of the screen.
I’d use something like the following 4 conditions:
“Cursor X position > (CameraX(“YourGUILayerNameHere”,0)-(CameraWidth(“YourGUILayerNameHere”,0))+2)”
“Cursor X position < (CameraX(“YourGUILayerNameHere”,0)+(CameraWidth(“YourGUILayerNameHere”,0))-2)”
“Cursor Y position > (CameraY(“YourGUILayerNameHere”,0)-(CameraHeight(“YourGUILayerNameHere”,0))+2)”
“Cursor X position < (CameraX(“YourGUILayerNameHere”,0)-(CameraWidth(“YourGUILayerNameHere”,0))-2)”

This is basically saying “Confirm the mouse cursor is within the area of the camera center minus 1/2 the camera width (or height) by 2 pixels”

Note: If you do not have a layer for your GUI, this should still work with your base layer.

Tried both ways. It seems that once the mouse down action is started, there is no way to shut it off. Specifying the area the mouse can do a mouse down action doesn’t stop it from staying activated if the mouse leaves the game window. I wish there was an action that could activate a mouse release action. Then these would work. I’ll keep plugging away at it. Let me know if you can think of another way.

Can you show your updated events? I’m interested to see what you’ve got, as it worked for me in a quick test before I posted.