• Godot Help
  • How to cut off a sprite if it extends off the map.

Currently in my game, the player is able to shoot an orb somewhere and where it lands, it spawns a sprite in with some scripts. I am able to use the Tile Maps Z index property to make it goes behind walls, but right now if the player shoots it at a wall that's on the edge of the map, it goes outside.

Here is what I mean,

Example A:

Player shoots a projectile, it hits the wall and goes behind it when needed.

Example B:

Player shoots projectile at edge wall, you can see it go out of the boundaries a bit, which is want I don't want.

I'm using Godot 3, can anyone help me find a solution for this?

Use some tricks to limit your camera always inside of the room, so you cannot see the bubble go outside

    yikescloud

    Is there any other way? I'd rather not restrict the camera from the border of the level.

    The easiest solution would be to make an object that covers the outside, so the projectile is hidden behind it. You might just be able to duplicate part of your background. If your background moves, I suspect you could use a shader to copy it, though there's probably an easier way.

    Not sure if it's optimal but I've used the lighting system for this kind of thing. I.e. you have a Light2D with a texture which is just a white box that exactly fills the internal area of the level where you want the projectiles to appear. You set the masks such that the light affects the projectiles and nothing else, and then any part of the projectile that extends beyond the boundaries of the light texture won't be visible.

    Edit: I said the projectile wouldn't be visible "beyond the boundaries of the light texture" but I should have said "beyond the boundaries of the white box." I think for this to work the light texture actually has to have a buffer of transparent area outside the white box, and the projectiles will be invisible where the texture is transparent (when the Light2D mode is set properly).

      soundgnome Hey! Thanks for the idea, I'm trying this right now but it seems to just illuminate the part thats in the light and not really do anything else, how do I make the sprite not be visible when outside of the light?

        acuaroo The Light2D has a property called Mode that affects how the light and lighted object interact, that might need adjustment. Honestly I have a hard time visualizing which mode should apply in a particular situation so I typically just try different ones (there are only four) until it looks the way I want. I think Mask is what you'd use in this situation so maybe try that one first.

        Also the light texture might need to be padded with enough transparency around the edges to cover the area where the projectiles might protrude, I think I remember running into a case where the thing I was hiding became visible again if it got past the edge of the light texture.