Repository navigation
Reject a ParallaxGroup depth of 0 when it's set - #2947
Merged
Merged
Conversation
pvcraven
force-pushed
the
fix/background-depth-zero
branch
from
October 8, 2026 17:21
2460323 to
9ee073d
Compare
ParallaxGroup divides the group offset by each layer's depth, so a
depth of 0 raised ZeroDivisionError the first time the offset changed,
far from where the depth was set. Setting a depth of 0, in any of the
four places a depth can be set, now raises a ValueError saying to use
float("inf") for a layer that doesn't scroll (#1551).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pvcraven
force-pushed
the
fix/background-depth-zero
branch
from
October 8, 2026 17:22
9ee073d to
e24b649
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the first item of #1551: a
ParallaxGrouplayer with a depth of 0.arcade.future.background.ParallaxGroupoffsets each layer by the group's offset divided by the layer's depth. A depth of 0 was accepted when set, then raisedZeroDivisionErrorthe first time the offset changed. That's usually inon_update, far from where the depth was set.The fix
Depth 0 is rejected when it's set: setting it now raises:
The check covers all four places a depth can be set: the constructor,
add(),change_depth()andgroup[i] = depth. A rejected depth isn't stored, so the group keeps working.Why not make depth 0 mean "doesn't scroll": layers scroll faster as their depth gets smaller, so 0 behaving like infinity would be surprising.
Pinning a layer already works: infinite depth gives an offset of 0. The class docstring now says so. That covers the
INFINITE_DEPTHitem in the issue without a new constant.Not in this PR
#1551 also asks for an initial offset per layer and a helper to sync the offset from a camera. Those are enhancements, so the issue stays open for them.
Tests
New
tests/unit/test_background_parallax_group.py;ParallaxGrouphad no tests before:The 5 background examples run. Full suite: 1759 passed. ruff, mypy and pyright all pass.
The changelog has an entry under Unreleased → Fixes.
🤖 Generated with Claude Code