How to crop sprite at certain coordinates with a radius?

What I am trying to do is to make a terrain destruction effect by cropping platform around missile when it touches the it with a certain radius. (See image below) How can I do that?

Both missile and platform objects would use physics behavior.
I tried messing around with masking, and implementing this example with some changes, but I just couldn’t get it to work.

Any idea is welcomed.

I haven’t tried this feature yet, but you’re on the right path.
Look at the events of the example, look for the part that destroys terrain and try to use the same actions, with the conditions you want.

I haven’t experimented with masking so far, but from what I saw it can’t be done because in example terrain is used as a mask of shape painter, which makes it visible only when shape painter is used. In my game I need quite opposite. I need terrain to be visible all the time, and removed only when shape painter is used at random coordinates with a radius.

You should definitely experiment with that because it does exactly what you want.

The shape painter is the mask and not the terrain.

That’s exactly how it works and it is up to you to decide what is visible through the mask.

You need two background sprites (or more - depends on your setup). One for your destructed and one for your undestructed landscape. You mask the destructed landscape with the shape painter (the sprite is on top of the undestructed background in the scene). When the missile collides with the undestructed ground you paint a circle with the shape painter and with the radius you want at the place of impact. Because this circle functions as a mask it will make the other background sprite (the destructed landscape) visible.

1 Like

As I mentioned, I am not experienced with masking because I haven’t tried using it so far, but I did tried something and partially it works. I have put a copy of a background in front of everything as a mask.
I couldn’t use destroyed terrain as a mask as u mentioned because terrain will be destroyed dynamically, anywhere where missile lands, so I can’t know how it will look like.

There is one problem I ran with masking. Since terrain is just masked, instead of actually destroyed, if missile hits masked part, terrain won’t destroy anymore because it’s not really destroyed and since missile is in collision with the part behind the mask it’s masking the already masked part.

Also, since I am using physics (I need it), player still collides with terrain even after masked.


Download Example:

This is unlikely to be compatible with Physics. Why do you need it?

The example that you use is actually about creating new platforms with the masking- and marching square- extensions. So the masked area becomes an object the player or other objects can interact with. As far as I understood that is not what you want, you just need to mask destroyed areas, right?

Yes, I understand. There are different ways to show the aftermath of the destruction, sometimes there would be some remains of the destroyed area as a background, but that is not a must. For the hills you need a sprite that shows the background anyway.

This are my events:

and this is what the scene looks like:

when I click with the left mouse button (in your case that would be the impact of the bombs) I create circles and “destroy” the hills:

And this is the scene in the editor. I have changed the background color to make the background sprite of the same color better visible. I also dragged it down a little bit, it needs to be exactly aligned to the hills.

It gives me the same results. As I mentioned, I am using physics engine for bullet, player and terrain. So whenever I “destroy” terrain once, it can’t be destroyed on that same spot anymore. Try spawning bullets at the same position with physics and you’ll see what I mean.

It is can be deleted when you use mouse as in your example, but with bullets it won’t work as shown here

What I can catch from the video is that your bombs are not deleted. They just pile up and therefore later bombs don’t collide with the ground. I am not sure why they are obstructed by the masking (do you still have the marching squares-functions in your events?). Changing their z-order could maybe work to make them visible. But in general you want to delete them after they hit the ground and explode. It would be extremely helpful, if you would post your events.

Yes, and the big question is why? Why is it necessary for the ground to be a physics object when it is just destroyed by the bombs? Same is true for the bombs. If they just drop and explode, physics is not necessary at all. What does your player do to be simulated as a physics object in your game? If you would describe your game a bit, it would probably help to point you in the right direction.

These are my events, and the full project can be found here

Anyway, I need physics because of different type of bombs, missiles, etc my game will have. Those weapons will be tank’s equipment with different sizes and weight. Also, tanks will be different in size, weight and features. So I need physics gravity, impulse, and everything else that platformer behavior doesn’t have.

The platformer behavior has gravity and forces (impulses), so I still don’t think you need Physics.

Just to add to what Gruk wrote:

Missiles and bombs have probably different ranges, which is something you can solve by applying different values to their movement. For the trajectory of some shells, physics could be useful but not really for the collision, unless you want to bounce missiles and bombs off the ground. If you want physics related destruction of your ground you would need to build it completely with smaller physics objects, which could be - depending on the size of your scene - very heavy on the performance.

Generally, the degree of destruction is something you control be applying different explosion animations (+ collisions) and for masking (the destruction) it is about drawing circles with different diameters. If you want the ground collision-wise to adjust to the destruction then the marching square example is exactly what you want. At the moment, it seems, you are just not using it properly.

The consequence of tank size and weight is probably speed and health points, for both you don’t need any physics (unless you want to crash them into each other and let them flip over or something like that).

Anyway, it is your game and you decide how you want to make it, most of the things you describe can be done without physics applied, which is less heavy for the system and gives you more control over what actually happens in the game.

I would suggest to find a game that has similar mechanics and figure out how the developers implemented them.

1 Like

Just an update for understanding the problem with the bombs:

The destructible platform example has a debugging view that shows the creation of the squares. It also shows that if you drop something and let it collide with the platform, the original measurements of the platform sprite-object are taken into account (the line with the blue arrow in the image below).

This is because the shape painter is responsible for creating the squares and not the sprite that is colliding. That’s why dropping several bombs on one spot does not change the initial destruction as the shape painter is not getting further below.
Letting the bomb drop within the platform sprite creates the shape painter and therefore changes the mask.

Unfortunately I have no good idea at the moment how this can be solved, there might be a way but probably it won’t be very simple.

1 Like

Yes, there would be bouncy bombs, launch equipment to launch tank in the air, shooting rotating blades, etc. Ig all it’s left to do is to wait and hope that GD team started or at least have in plan to start converting that possibility from older GDevelop 4 version. I saw that it has destructible terrain feature.