should viewport work with unbound scrolling?

Get help using Construct 3!

Post » Sun Jun 18, 2017 9:03 am

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?
B
43
S
22
G
20
Posts: 735
Reputation: 11,977

Post » Mon Jun 19, 2017 4:53 am

@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.
B
94
S
33
G
20
Posts: 438
Reputation: 17,605

Post » Mon Jun 19, 2017 3:45 pm

@AllanR Thanks and good explination, you were right i was wrongly assuming viewport left was 0.
B
43
S
22
G
20
Posts: 735
Reputation: 11,977

Post » Mon Jun 19, 2017 4:21 pm

@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.
B
94
S
33
G
20
Posts: 438
Reputation: 17,605

Post » Mon Jun 19, 2017 7:11 pm

very useful, I'll keep that mind.

Thanks @AllanR
B
43
S
22
G
20
Posts: 735
Reputation: 11,977


Return to How do I...?

Who is online

Users browsing this forum: UberLou and 0 guests