1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

HTML5 Need help detecting when the mouse leaves the canvas area

Discussion in 'Programming' started by Uhfgood, Jan 7, 2017.

  1. Uhfgood

    Uhfgood Member

    Joined:
    Sep 26, 2016
    Posts:
    87
    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?
     
  2. Laurent57

    Laurent57 Member

    Joined:
    Nov 20, 2016
    Posts:
    154
    Can't you check the coordinates of the mouse and use mouse_clear if the pointer is outside?
     
  3. Uhfgood

    Uhfgood Member

    Joined:
    Sep 26, 2016
    Posts:
    87
    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.
     
  4. Mholmes3038

    Mholmes3038 Member

    Joined:
    Jan 7, 2017
    Posts:
    18
    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.
     
  5. Uhfgood

    Uhfgood Member

    Joined:
    Sep 26, 2016
    Posts:
    87
    I am using Gamemaker studio 1.4 -- the html5 target -- so unless I go into the javascript itself this doesn't help much.
     
  6. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,264
    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.
     
  7. Laurent57

    Laurent57 Member

    Joined:
    Nov 20, 2016
    Posts:
    154
    So if you're outside then mouse_clear(mb_left) ?
    Sorry, i have GM8...
     
  8. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,627
    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.
     
  9. Uhfgood

    Uhfgood Member

    Joined:
    Sep 26, 2016
    Posts:
    87
    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
     
  10. Uhfgood

    Uhfgood Member

    Joined:
    Sep 26, 2016
    Posts:
    87
    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)
     
  11. Uhfgood

    Uhfgood Member

    Joined:
    Sep 26, 2016
    Posts:
    87
    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)
     
  12. Uhfgood

    Uhfgood Member

    Joined:
    Sep 26, 2016
    Posts:
    87
    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.
     
  13. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,627
    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.
     
  14. Uhfgood

    Uhfgood Member

    Joined:
    Sep 26, 2016
    Posts:
    87
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice