HTML5 Mouse leaving canvas area in html5

U

Uhfgood

Guest
I've implemented some code that allows me to drag the paddle in my breakout game let or right sort of like a scroll bar. Only if I hold down the button drag it outside the canvas area, let go of the button while outside of the canvas area, I then move back into the canvas, and the mouse automatically moves as though I were still dragging it. Right now I'm detecting if the paddle has hit the wall objects, and then I act as though I released the left mouse button. But it still does this crazy thing...

Code below:
Code:
var hit_wall = false;

if( is_dragging == false )
{
    if( mouse_check_button( mb_left ) &&
        collision_point( mouse_x, mouse_y, self, false, false ) )
    {
        is_dragging = true;
        prev_mouse_x = mouse_x;
    }
}
else
{
    var mouse_travel = mouse_x - prev_mouse_x;
    if( !place_meeting(x + mouse_travel, y, obj_left_wall) &&
        !place_meeting(x + mouse_travel, y, obj_right_wall) )
        x += mouse_travel;
    else
    {
        hit_wall = true;
        if( mouse_travel < 0 )
        {
            // left
            var dis = distance_to_object( obj_left_wall );
            if( dis < abs( mouse_travel ) )
            {
                x -= ( dis - 1 );
            }
        }
        else
        {
            // right
            var dis = distance_to_object( obj_right_wall );
            if( dis < abs( mouse_travel ) )
            {
                x += ( dis - 1 );
            }
        }
    }
    
    prev_mouse_x = mouse_x;
}
if( !mouse_check_button( mb_left ) || hit_wall )
{
    is_dragging = false;
    speed = 0;
    prev_mouse_x = mouse_x;
    //if( hit_wall ) show_message( "hit wall" );
}
 
L

Laurent57

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

Uhfgood

Guest
Can't you check the coordinates of the mouse and use mouse_clear if the pointer is outside?
Tried device_mouse_raw_x but it only reports the position if it's over the canvas area -- the above code attempts to turn off mouse dragging when the paddle hits the wall objects, but this doesn't really work either.
 
Top