dcsimg
A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: [F8] Mouse outside window question

  1. #1
    Junior Member
    Join Date
    Feb 2007
    Posts
    2

    [F8] Mouse outside window question

    I have a problem with my game(s) when ever the mouse is moved past the window edge I loose control in the game. So how can I set it up so the mouse either believes its always in my playing window or have the game pause when it leaves the window?

    Sorry if this has been asked a half a billion times. I did try a search but found tons of info but none relating to this issue. So if there a great thread on dealing with this a simple link will make me a very happy camper.

  2. #2
    Software Developer mickm's Avatar
    Join Date
    Sep 2006
    Location
    Kingston [ON]
    Posts
    115
    This is probably not the best solution but...

    1. Create a variable that will tell your objects (or main function) that the game is paused. (ie: blnPaused:Boolean )

    2. In your frame have it constantly check the mouse position.
    Code:
    If (_root._xmouse < 0 || _root._xmouse > Stage.width || _root._ymouse  < 0 || _root._ymouse is > Stage.height) blnPaused = true;
    else blnPaused = false;
    Not sure if that will work i just typed it out, didn't actually try it. But you should get the idea.
    Post you game for free at Gamestack.org. We send the user straight to your website, no iFrames or other leeching methods.

    Please check out Gamestack.org for more information.

  3. #3
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    mickm, that won't work, since the mouse stops being tracked before it reaches those coordinate values.
    http://www.birchlabs.co.uk/
    You know you want to.

  4. #4
    Junior Member
    Join Date
    Feb 2007
    Posts
    2
    Yeah thats why I ran into problems I have no idea how to know if the mouse is in or out of the window. If I knew how to detect that its a breeze to figure out how I want to deal with it.

  5. #5
    Please, Call Me Bob trogdor458's Avatar
    Join Date
    Aug 2006
    Location
    Pensacola, FL
    Posts
    915
    I had to deal with this problem once, made a giant button to solve it
    if your cursor goes off screen, the button will know that there is no mouse over it

  6. #6
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    Above is what I was going to suggest. The only problem is that it is really annoying to always have the hand mouse thingy. Of course, if its click to shoot it may be a bonus to have the hand cursor.

    There is also a _focus or getFocus property/function in flash, I have no idea what it does (or if its even called that) but it may be worth looking into.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  7. #7
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    there is some command to have the hand mouse thing not show up...
    mmm signature

  8. #8
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140
    not the best solution but it works, just check in your enterFrame for a pause variable

    Code:
    var ox = _xmouse
    var oy = _ymouse
    var pause = false
    
    function checkMouse(){
    	
    	var vx = _xmouse - ox
    	var vy = _ymouse - oy
    	
    	var px = _xmouse + vx * 2
    	var py = _ymouse + vy * 2
    	
    	ox = _xmouse
    	oy = _ymouse
    
    	pause = px <= 0 || px >= Stage.width || py <= 0 || py >= Stage.height
    }
    
    function game(){
    	
    	debug.text = "pause"
    	
    	if(pause) return
    	
    	debug.text = "playing"
    }
    
    onMouseMove = checkMouse
    onEnterFrame = game
    Last edited by mr_malee; 02-21-2007 at 11:50 PM.
    lather yourself up with soap - soap arcade

  9. #9
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    ChaseNYC, the command is:

    myButton.useHandCursor = false;
    http://www.birchlabs.co.uk/
    You know you want to.

  10. #10
    Truimagz.com everfornever's Avatar
    Join Date
    Sep 2006
    Location
    St. Louis
    Posts
    1,306
    Id say do the button thing and just us Mouse.hide(); then if you actually need a cursor for your game, make one, and use cursor._x = _xmouse; cursor._y = _ymouse

  11. #11
    Please, Call Me Bob trogdor458's Avatar
    Join Date
    Aug 2006
    Location
    Pensacola, FL
    Posts
    915
    I thought there was a way to change what your cursor looked like without said method...doesnt matter though, with that method you can create pretty dang good effects (although its not much use in-game)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center