How do I get the scale of the browser window

0 favourites
  • 4 posts
From the Asset Store
This is a single chapter from the Construct Starter Kit Collection and the Student Workbook from the Workshop.
  • I am new to Construct 2 but not to programming. As a small test, I have implemented "zoom towards mouse pointer" like in Google Maps.

    As target for the zoom, I use a Sprite. Since I want to be able to change this sprite dynamically, to a sprite with a different size and different aspect ratio, I have set the layout size to a very big value and handle scale limiting when zooming out myself. As far as I have found out, it is impossible to change the size of the layout itself at runtime.

    When the user zooms out using th emouse wheel, the layer scale of the sprite is changed, and ViewportLeft, -Right, -Top and -Bottom are used to detect if any edge of the sprite is inside the visible area. In that case, scrollx and scrolly are adjusted accordingly.

    Sooner or later when zooming out, both the opposite sides of the sprite become visible, and therefore, a minimum scale (maximum zoom out) that can be allowed has to be calculated. I do this by dividing Browser.ScreenWidth by the width of the sprite. I then do the same for height and choose the maximum value as the limit. All this works fine, as long as the browser covers the entire screen.

    However, if the user resizes the browser, the above scale limit calculation stops working. The problem here is that the browser itself (I have tested with Google Chrome) automatically scales the contents when the browser window is resized. This automatic scaling breaks the calculation and I have found no way to handle this.

    I can see three different solutions:

    • somehow find the automatic scale change and compensate for this mathematically (best),
    • somehow stop the browser from scaling the contents automatically (acceptable),
    • somehow prevent the user from resizing the browser window (worst).

    Can anyone suggest how this could be done, or if there are better ways to do it? Is it possible to determine the value of the automatic scaling that the browser applies?

    Thanks in advance,


  • Can you post your capx or an example? Hard to visualize your problem. Your approach seems complicated for something like zooming, although I assume you have your reasons.

    Have you tried using the Browser - On Resized condition to recalculate your numbers when the browser gets resized with the new browser window dimensions, or possibly adjust the size of your helper sprite accordingly?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmm? You can set the initial view scale on the layout view commands.

    I don't think you can keep the user or device it is played on from rescaling so you may have to use a scale options menu or warn users to not change the scale but maybe someone knows a different way.

  • Thanks for your answers. I realized that I had overcomplicated things and was able to make it work. Construct is amazing, but it takes some time to get used to it!

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