• 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!

HTML5 Need help detecting when the mouse leaves the canvas area

U

Uhfgood

Guest
This is probably the last post I'll do in the subject. I figure the only reason I haven't been responded to before is because I'm not defining the problem well enough or I'm not clear enough.

So basically in my breakout clone I'm making the player drag the paddle left or right like a scroll bar. This means left clicking on the paddle holding it down and moving it left or right. When you let up on the button it stops being dragged. I have a small problem where if you are still holding down the mouse button when the mouse leaves the canvas (game) area it will not register the mouse button as being released. So basically I want it to stop dragging the paddle if you let go of the button OR the mouse leaves the canvas. Right now if you leave the canvas area and let go of the mouse button and move the mouse back onto the canvas, the paddle moves as though you're still dragging it. I want you to have to manually "re-drag" it or basically you have to drag it again by hitting the mouse button on the paddle before it will move again.

I put a step event in the paddle object and you can find the code here: https://forum.yoyogames.com/index.php?threads/mouse-leaving-canvas-area-in-html5.16521/

So can anyone help me?
 
L

Laurent57

Guest
Can't you check the coordinates of the mouse and use mouse_clear if the pointer is outside?
 
U

Uhfgood

Guest
I tried tracking the coordinates by using device_mouse_raw_x -- however it will only report it if you're over the canvas (over the game itself). It does return the correct numbers, but it won't give me a position anywhere else in the browser, just over the canvas (game) area.
 
M

Mholmes3038

Guest
I hope this helps:

http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/

I'm a ASP .Net dev so I don't know much about HTML5 more on the ASP/HTML/JavaScript side. My understanding though of browser games similar to this would be when the player leaves the canvas, the position typically just stops until the player re enters the canvas. If your attempting to get the mouse location via outside the HTML form its self, you might look at JavaScript to capture the clients mouse location. Since the issue would be a client side problem, I would think JavaScript would be the direction you need to go / look into for a solution.
 
U

Uhfgood

Guest
I am using Gamemaker studio 1.4 -- the html5 target -- so unless I go into the javascript itself this doesn't help much.
 
Have you tried using the Event : Mouse->Global Mouse->Global Left Released event to turn off the dragging? I haven't made an HTML5 game unfortunately so haven't tested this.
 
L

Laurent57

Guest
So if you're outside then mouse_clear(mb_left) ?
Sorry, i have GM8...
 
U

Uhfgood

Guest
Laurent57 - mouse clear doesn't work because it's not a mouse problem -- I did try it, but it still did the same thing.
IndianaBones - Just tried it, it still doesn't work... it has something to do with how I detect dragging I think
 
U

Uhfgood

Guest
Let's hope so, this is the 3rd I've seen in 2 days - why not just edit your original post?

You need to give people a little time to respond.
Whenever I've edited posts I didn't notice it getting bumped back to the top of the list -- so instead of getting buried in an avalanche of other posts I put up a new one. (After a day or so nobody tends to see my posts anymore - at least that has been my experience -- if I'm wrong, i'll start trying to edit my posts to bump them)
 
U

Uhfgood

Guest
I've even used "mouse_clear" right at the top of the code in the step event

It's still registering a mouse button (using mouse_check_button)
 
U

Uhfgood

Guest
I changed to mouse_check_button_pressed --- what happens is then I press it and it seems to work normal, i move it off the canvas and move it back on, and of course it doesn't move the paddle, but in order to move the paddle again I have to actually click and release it first before attempting to drag the paddle again.

This is basically showing me that it still registers as a mouse down even if you leave and come back to the canvas. mouse_clear doesn't seem to have any effect.

I guess one other thing I could have is some sort of invisible control object, put the script in there, and when I want to move the paddle I'll move it using the 'with' keyword. I'm not sure if this is the best course of action, but I'm thinking it may work.
 

rIKmAN

Member
Whenever I've edited posts I didn't notice it getting bumped back to the top of the list -- so instead of getting buried in an avalanche of other posts I put up a new one. (After a day or so nobody tends to see my posts anymore - at least that has been my experience -- if I'm wrong, i'll start trying to edit my posts to bump them)
If everyone did that the forum would be full of duplicate posts and people trying to get attention - basically a nightmare.

You've just done the same thing again by replying to yourself 3 times in 30mins to bump it to the top of the list - edit your posts to add additional information.

You have 3 threads all asking the same question, which means it's harder to keep track of replies for you, as well as clogging the New Threads for other users.

Check the forum rules, I think it's 48hrs before you bump your own thread, this gives people chance to reply - not everyone checks the forum every 5mins and people have lives, especially when it's the weekend.
 
U

Uhfgood

Guest
I didn't reply to myself to bump it, if it did bump it I apologize. Usually when I'm having a problem, and think I've used all my available options I will stop, and then 5 minutes later or so, have another idea, then I go and code it, which usually turns out to be wrong and then I do it again. Each time I replied I had tried something new. Actually replied twice in relation to my problem. And once having to do with multiple posts.
 
Top