Prevent sprite from getting rendered outside specific area

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sigma-One
:warning: Old Version Published before Godot 3 was released.

I have set up a hallway with a background that moves vertically in relation with the player’s movements, and it is working fine. The hallway background is taller than the hallway so it does not leave gaps in the background when moving. But I want it to not render outside the hallway, as this would cover the space background visible on the outside. The problem is that I have no idea if this is possible, and if it is, how it is done. An area in which the background is allowed to render isn’t possible as the hallway’s height may vary.

:bust_in_silhouette: Reply From: avencherus

If I understand you correctly, you might to clip some image to another.

You should try using Polygon2D for your background. It accepts a texture, and it has offsets you can manipulate to move that texture around.

You can then draw the polygon around the other area, and the texture will be confined within that.

This worked, after I decided to drop height variances from the hallway because they wouldn’t fit on some mobile device’s screens. Thanks!

Sigma-One | 2017-08-02 09:54

You’re welcome, glad it was what you were looking for.

avencherus | 2017-08-02 10:14