Is there a way to clip (or mask) parallax layers or canvas layers that follow the camera?

Godot Version

Godot 4.3
Hey :slight_smile:

Question

I’m working on creating 2D rooms with multiple parallax layers (furniture, walls, windows, etc.). I’ve set up two ParallaxLayer2D nodes, and they work as intended.

However, when the player moves to Room 2, the layers from Room 1 are still visible.

Is there a way to make Layers 1 and 2 visible only in their respective rooms? I tried using a Sprite2D with the ClipChildren (Clip Only) option as a parent node, but it only works with other sprites and doesn’t affect parallax layers or canvas items. Also I’ve tried to use Viewports for each room but ParallaxLayer2D did not move with the camera.

Is there a way to hide Room 1’s layers when the player is in Room 2 without manually managing the visibility based on the player’s position? I’d prefer to avoid that approach since it feels clumsy.

I’m not entirely sure what you’re asking, but if it is what I think it is, you can just place the room extents in a Control and set it to clip contents. The only drawback is that Control nodes currently don’t work with clip contents when rotating.

1 Like

Thank you for your reply!

For some reason, clipping (masking) works perfectly with simple Sprite2D nodes but doesn’t seem to work with parallax layers.

However, I found a solution: a custom Parallax node available here: Parallax 2D node - Godot Asset Library

This node adjusts the position of a sprite based on the viewport’s position, allowing clipping to work seamlessly.

Here’s what I achieved using this approach:

If you know better solution, please let me know. :slight_smile:

I assume you’re using an older version of Godot? Parallax2D is a built in node in 4.3+, where ParallaxBackground and ParallaxLayer is deprecated, so that would be a better way to go.