Make screen black on focus lost?

0 favourites
  • 10 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • Hi I am trying to figure a way to when my browser is not in focus that I can make a different layout visible. For the purpose of not being able to capture the image with a screen capture....

    Idea is for an art gallerey that when focus is lost the screen goes black....

    Upon pressing any key the screen will go black....

    theory is two layers on visible as gallerey and controls to scroll through.

    Other being the black layer which will be on top but invisible until needed.

    So basicly I need to know if there is a way to check for the browser being in focus or not.

    Thanks I am working on this but do not see this feature?

  • Games

    Found this under 'Browser' in the manual:

    "Page is visible

    True if the page the HTML5 game is running on is currently visible. The page counts as hidden if the window is minimised, the page is in a different tab to the one being viewed, or on a mobile device when the app goes in to the background. When the page is hidden the game automatically pauses."

    I haven't used it, but it sounds like it would fit your needs. Add an event 'Browser - Page is Visible'; make your black overlay invisible for that condition and visible on an 'Else' condition.

    Take care!

  • Thanks for the reply I did see and try as you also have written prior to my posting the question.

    It seems this will only check for is the tab the game is on active. When tab is not active the game is not visible so no need for cover up. I want this to be when the actual browser is not in focus. Such as a screen capture software takes focus. and also will use on any key pressed to prevent shortcuts to launch a capture device.

    an example to test would be have game running and then open any window but only cover part of the browser. There should be a way to know the game is out of focus at that point. perhaps it is not in CS2 ability yet.

  • Games

    Whenever those conditions that you mention are present, the game pauses. So having your game window partially covered should pause the game, correct?

    Maybe the 'Browser > On Suspended' event would work? Black out the screen if it's suspended and show the screen when it's resumed? (Browser > On Resumed)

  • Here is the sample I been working on it shows the last suggestion still not what I am thinking should happen.

    Again Thanks always nice to get replies :)

    https://dl.dropboxusercontent.com/u/223672920/hide%20objects.capx

  • Games

    Hmmm... it seems you need a very specific function for this to work. Probably beyond my expertise! Hopefully, someone more knowledgeable swoops in with a solution.

    Good luck!

  • Thanks Again space Ape.

    I tried a few other ways to achieve my deired result and of course hit walls there too :)

    I am curious about execute Javascript as perhaps my solution. I was researching browser focus and ca,e across this Demo that is what I want to do. In that demo the page goes black if browser loses focus. Even a right click on the status bar will invoke it. this could be perfect if I can understand how if at all possible to use.

    http://www.thefutureoftheweb.com/demo/2007-05-16-detect-browser-window-focus/

  • These days clicking the print screen key will capture the screen without any 3rd party software or anything else needing to be opened. Programs running wont even lose focus so you may be attempting to do something that isn't going to end up helping much in the long run. (Hopefully I'm wrong, just something to keep in mind.)

  • Burvey I think you may be right I thought that using the command like on any key pressed with my above request would cover this. However I moved on to the any key pressed and while I can disable the windows built in screen capture I was unsuccessful in detecting a hotkey prior too it already grabbing the screenshot. That's a bummer. Thanks for Reply I am going to look further I now know it's not built in and will need some form of coding on my part so if I am going to code it mayve I can code a key press checking sytem that will go in front of other hotkeys.... Just rambling here LOL

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You really got me thinking about ways to beat the screen capture. I did some searching around and there is one novel idea, but I'm not sure if it would work in your case, or at all for that matter. But the idea is to take your images and pixelate them down into 3 or 4 different images then switch between them quickly enough that the human eye can't tell the difference. In theory when the computer gets a screenshot it will only get one part of the image filled with transparent holes.

    Good luck, I hope you can figure something out. Please let us know if you do.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)