Skip to content

Reject a ParallaxGroup depth of 0 when it's set - #2947

Merged
pvcraven merged 1 commit into
developmentfrom
fix/background-depth-zero
Oct 8, 2026
Merged

pvcraven merged 1 commit into
developmentfrom
fix/background-depth-zero

Conversation

@pvcraven

@pvcraven pvcraven commented Oct 8, 2026

Copy link
Copy Markdown
Member

Summary

Fixes the first item of #1551: a ParallaxGroup layer with a depth of 0.

arcade.future.background.ParallaxGroup offsets each layer by the group's offset divided by the layer's depth. A depth of 0 was accepted when set, then raised ZeroDivisionError the first time the offset changed. That's usually in on_update, far from where the depth was set.

The fix

  • Depth 0 is rejected when it's set: setting it now raises:

    A ParallaxGroup depth can't be 0. For a layer that doesn't scroll, use float('inf').

    The check covers all four places a depth can be set: the constructor, add(), change_depth() and group[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_DEPTH item 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; ParallaxGroup had no tests before:

  • The offset is divided by each layer's depth.
  • Infinite depth doesn't scroll.
  • Depth 0 is rejected in all four places, and nothing is stored when it is. This test fails on development.

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

@pvcraven
pvcraven force-pushed the fix/background-depth-zero branch from 2460323 to 9ee073d Compare October 8, 2026 17:21
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
pvcraven force-pushed the fix/background-depth-zero branch from 9ee073d to e24b649 Compare October 8, 2026 17:22
@pvcraven
pvcraven merged commit fb7a4e3 into development Oct 8, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant