0 Favourites

should viewport work with unbound scrolling?

  • I want to always have a sprites width be the width of the screen regardless of if the user resizes the window.

    I can do set sprite width to viewport(left) + viewport(right), it works but not when unboundscrolling is checked.

    Is this correct or a bug?

  • Ethan,

    That is working correctly. With unbounded scrolling, viewport(left) could be anything: 12,453,121 or -7,231

    so adding viewport(left) + viewport(right) may give you a very large positive or negative number - way bigger than the width of the screen.

    You want to set the sprite width to viewport(right) - viewport(left)

    a couple months ago I was working on an app that always used the full screen on a cell phone by using unbounded scrolling. I was amazed at how many bugs I created because of assuming viewport(left) is zero. Things like centring a button on the screen - you would think it is the width divided by two (viewport(right) - viewport(left)) / 2. But that assumes the left edge is at 0. So, you have to always start from the actual left viewport coordinate and do something like:

    ViewportLeft("HUD") + (ViewportRight("HUD") - ViewportLeft("HUD")) / 2

    And, of course, you have to remember that the top of the screen isn't zero either.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • AllanR Thanks and good explination, you were right i was wrongly assuming viewport left was 0.

  • Ethan

    It was surprising how subtle that assumption can be, and how it can work its way into things.

    Another issue I ran into was updating the screen after the user changes the window size or changes screen orientation. It takes the browser object a while (about a tenth of a second) to get the new viewport dimensions - so you can clear the screen when the browser On resized event fires, but you have to add a Wait to get the new dimensions and update where things should be.

  • very useful, I'll keep that mind.

    Thanks AllanR

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