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