A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: How to pause a game when switching windows

  1. #1
    Senior Member
    Join Date
    Feb 2004
    Posts
    782

    How to pause a game when switching windows

    I've noticed since the last few version of flash player that when your main view isn't focused on the flash game, it tends to mess the game up.

    How do I make it so the game automatically pauses when I switch to a new window or lose focus.
    Flash Ninja Clan - Games and cartoons

  2. #2
    Member
    Join Date
    Jun 2010
    Posts
    32
    it depends on what type of game you have, but generally for a mouse intensive game, you can say if _root._xmouse,_root._ymouse is not in the bounds (by creating an invisible background object that works as a checker) it pauses, or if you wanted to do a click test versus a position test you could say more formally

    Code:
    onClipEvent(enterFrame)
    {
    	if(this.hitTest(_root._xmouse,_root._ymouse) && "mouse is not pressed"){}
                 else{gotoAndStop("Pause_Frame")}
    }
    i forgot how to put "mouse is not pressed" in terms as2 can understand :P but that's your general idea. You would probably have to set a variable equal to the mouse not being pressed, or something like that.

    if you want something a little more formal, let me know and i'll get on it

  3. #3
    Senior Member
    Join Date
    Feb 2004
    Posts
    782
    So basically I have to create a clip the size of the stage right?
    Flash Ninja Clan - Games and cartoons

  4. #4
    Member
    Join Date
    Jun 2010
    Posts
    32
    if you were to do it this way, then yes. I personally don't see anyway around this anyway, because for most games you'll have a background object anyway, and that should due most of the time anyway (even in side scrolling games where the background is off the page, it shouldn't matter because the moust wouldn't be clicking in the program)

    hopefully that made sense :P

  5. #5
    Senior Member
    Join Date
    Feb 2004
    Posts
    782
    weird, _root._xmouse and _root._ymouse seem not to be working
    Flash Ninja Clan - Games and cartoons

  6. #6
    Senior Member
    Join Date
    Feb 2004
    Posts
    782
    I'm using this code:
    Code:
    onClipEvent(enterFrame)
    {
    	trace(_root._xmouse);
    	trace(_root._ymouse);
    	if((_root._xmouse<650&&_root._xmouse>0)&&(_root._ymouse>0&&_root._ymouse<550))
    	{
    		trace("onhit");
    	}
        else
    	{
    	   trace("offhit");
    	}
    }
    And regardless of where I move my mouse, it still thinks I'm within bounds. I tried toe hitTest thing too and it always thinks I'm in bounds.

    My trace always indicates that it thinks that X and Y mouse are in bounds. WTH?
    Flash Ninja Clan - Games and cartoons

  7. #7
    Member
    Join Date
    Jun 2010
    Posts
    32
    well i don't see anything wrong with your code other than the third line, i'm not sure if you can hold arguments in parenthesis like that, and honestly you could take them out and it would work the same anyway.

    though this is odd. Perhaps you could try something like this instead?
    Code:
    onClipEvent(enterFrame)
    {
    	var position1
    	function onLoad()
    	{
    		position1 = 1
    	}
    	function onEnterFrame()
    	{
    		if(_root._xmouse > 0 && _root._xmouse <650 &&
    		   _root._ymouse >0 && _root._ymouse < 550))
    		   {position1 = 1}
    		else{position1 = -1}
    		if(position1 < 0){gotoAndPlay("Pause_Frame")}
    	}
    }
    *note this can go in a controller class definition instead (and probably should)
    HOWEVER, I doubt this will work either because I don't think a swf file recognizes the global position of the mouse on the screen, but only the position of the mouse inside the swf itself. This means that you'd have to work with PHP or HTML or whatever else on an internet site to have this effect OR you'd have to work with fscommands, which i've not done in the past and thus couldn't help you.

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