How do I get the scale of the browser window

Just started using Construct 2? Post your questions here

Post » Mon Mar 13, 2017 10:47 am

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,

Mikael
B
12
S
4
Posts: 3
Reputation: 756

Post » Tue Mar 14, 2017 8:44 pm

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?
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Wed Mar 15, 2017 6:34 pm

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.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,780

Post » Sat Mar 18, 2017 6:33 pm

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!
B
12
S
4
Posts: 3
Reputation: 756


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 4 guests