I am working on a 2D platformer game with some backgrounds on the z-axis to achieve a parallax effect. It works quite well but I would like to mask the background (red on the picture) when it’s out of the foreground.
Does anyone have an Idea if it could work ? I’m struggling with it because it’s just a perspective effect and the background is at the same x and y position as the foreground…
I appreciate any help !
Thank for answering !
Sorry if my question was unclear, I have one foreground (characters and platforms) and one background.
The background (z=3) is just behind the foreground (z=0)
(The depth of field effect is applied on the Background).
The parallax effect works well but when the camera moves, sometimes, my background looks “out of place”.
That effect is caused by the perspective Camera.
I would like to hide the red part, as if the foreground were masking the background.
Both background and foreground have the same x and y position.
Honestly, I don’t know if it’s a thing or if I should just paint in black what’s out of bounds in the foreground to hide the background.
Thank you in advance for your help !
I would just insert an extra stretched bunch of black plates where you need them… you certainly COULD do it with shader tricks and stencils / masks, but if you just made a single 32x32 black tile sprite and stretched/inserted it as many times as necessary, it might be the fastest simplest solution. It would use almost no memory either.