Scrolling at different zoom levels/layer scales

0 favourites
  • 7 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • I'm developing a space game, and the user can zoom out to see more of the playing area. I do this by halving the `LayerScale` for each layer each time they press the 'zoom out' key.

    1 is fully zoomed, 0.125 is full zoomed out.

    The Problem: I have a drag-to-scroll function, which works fine on zoom level 1, but when I zoom out, the scrolling/dragging speed is half each time. How do I keep the same scrolling/dragging speed (or do I need to increase it?)

    These are my events:

    I attempted to play with the dragging calculations in lines 11-12 (where the comment is - e.g. doubling different variables at smaller zoom levels), but that didn't work. 11-12 is now unused, so won't impact the overall function.


  • You have no speed element as I can tell.

  • You have no speed element as I can tell.

    Yes, because I don't know how/where to add a speed element, or what a speed element should look like...

  • (Bumping)

  • Only thing I would suggest is a lerp on the scroll.

    Something like set scrollx to lerp(scrollx, mouse.x, (msyspeed*LayerScale(layer))*dt))

    That gives you a speed, and a multiplier based on the layer scale.

    Grab to scroll can be a little more complicated: distance(tStartx,LayoutHeight/2,Touch.X,LayoutHeight/2)>128?lerp(scrollx,Touch.X>tStartx ?tStartx-distance(tStartx,LayoutHeight/2,Touch.X,LayoutHeight/2) :tStartx+distance(tStartx,LayoutHeight/2,Touch.X,LayoutHeight/2),1.5*dt) :scrollx

  • Thanks for the code! Would you mind breaking it down a bit more, so I know the best way to set those initial variables.

    Specifically, scrollx (should I create a new global variable, or somehow overwrite the system variable?), msyspeed, dt and tStartx.

    Also, where should I place the second code? Is that one event, or multiple?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Scrollx, and Scrolly are system expressions for the actual scroll.

    Myspeed is the speed in pixels you want to move.

    LayerScale(Layer) is the scale of the layer and its used as a multiplier. So if the scale is 1 Myspeed is unaffected. 2 twice as fast etc.

    The second formula is a different way to scroll. Its overly complicated so you might want to wait awhile to figure it out.

    Also Dt is the delta time, another system expression for the summation of the framerate.

    You should look that one up.

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