Bugfix: Scroll constraint favors top/left edge

For levels having a top/left scroll boundary, the top/left point takes
higher priority for resolving out-of-bounds scroll ranges instead of the
bottom/right.

This fixes a bug where you Zoom Out of a level far enough that the
entire boundaries of a Bounded level are smaller than the viewport into
the level. It could happen if playing normal levels in Play Mode on a
very high-resolution monitor. Previously, the level would anchor to the
bottom/right corner of your screen.

With the Zoom In/Out Feature this broke the ability to scroll well on
the level; so the easy fix is to put the X>0, Y>0 bounds check after the
above, so the level will hug the top/left corner of the screen which
fixes both problems.
This commit is contained in:
Noah 2021-09-12 15:59:40 -07:00
parent 21520e71e9
commit 0a1d86e1f5

View File

@ -67,18 +67,6 @@ func (w *Canvas) loopConstrainScroll() error {
var capped bool var capped bool
// Constrain the top and left edges.
if w.wallpaper.pageType > level.Unbounded {
if w.Scroll.X > 0 {
w.Scroll.X = 0
capped = true
}
if w.Scroll.Y > 0 {
w.Scroll.Y = 0
capped = true
}
}
// Constrain the bottom and right for limited world sizes. // Constrain the bottom and right for limited world sizes.
if w.wallpaper.pageType >= level.Bounded && if w.wallpaper.pageType >= level.Bounded &&
w.wallpaper.maxWidth+w.wallpaper.maxHeight > 0 { w.wallpaper.maxWidth+w.wallpaper.maxHeight > 0 {
@ -103,6 +91,18 @@ func (w *Canvas) loopConstrainScroll() error {
} }
} }
// Constrain the top and left edges.
if w.wallpaper.pageType > level.Unbounded {
if w.Scroll.X > 0 {
w.Scroll.X = 0
capped = true
}
if w.Scroll.Y > 0 {
w.Scroll.Y = 0
capped = true
}
}
if capped { if capped {
return errors.New("scroll limited by level constraint") return errors.New("scroll limited by level constraint")
} }