How to destroy your game floor per pixel

0

Attached Files

The following files have been attached to this tutorial:

.capx

tutorial-file.capx

Download now 188.83 KB

Stats

1,479 visits, 1,912 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 16 Aug, 2019. Last updated 23 Apr, 2020

Hi!

You're searching for a solution for a destroyable Floor? Then your exactly Right here!

I'll show you how you can get a destroyable Object for your game like in "Worms". But this will cost a lot of resources so find out if it’s not enough for you just dealing witch the "Destination out" effect (used in an example Project from scirra named "Light and Shadow".). But this will just have a visible effect so it doesn't change the collison of the object (hitbox).

So, let’s start!

Theoretical you could make an 1p x 1p object per pixel an let it destroy if it's on collision with another object. But this would only work on a NASA Computer. If you do this on your device, you just will get an error because it takes to much resources.

So, to let theory become praxis we have to save resources. To reach this we make an algorithm out of 3 Events. This algorithm will quarter the object (an box) so long as it collisions witch the destroyer object and it's not smaller than XYZ-pixels. Is the XYZ size reached the object will get destroyed.

To be sure, that XYZ will get reached every time exactly we use a two-system.

1 *2

2 *2

4 *2

8 *2

16 *2

32 *2

64 *2

128 *2

256 *2

512 etc.

The objects, which will get destroyed, will have the width and height of the bold written numbers.

Ok, for better understanding an example:

Our destroyer object is a circle and it is in collision with our floor object sized 512p x 512p. Our algorithm starts quartering the 512p x 512p objects, so it creates 4 new objects with the half of the height and width from the original object (so 256p x 256p). These objects will be placed in the four quarters of the original object. After this the original object will get destroyed and the algorithm repeat.

To get more understanding look at the tutorial file!

So, make this become real:

We need:

1x Sprite- Name: "Destroyer"; behaviours: (DragDrop); Image: (I just use a circle) -> The hitbox should be clear for a good result

1x Sprite- Name: "RedBall"; behaviours: (DragDrop), (Physics); Image: (I use a red Circle) -> I use the RedBall to proof that everything works so it isn't important for the process!

1x TiledBackground- Name: "Terrain", behaviours: (Physics -> set Immovable); Image: (use an 1p x 1p Image and give it a colour. I don't know but, in my case, this saves resources. Don't worry our floor will get his texture through another objects)

1x Function

1x Mouse

Your layout should look like this:

So next: SCRIPTING!

We need 4 variables, all number typed: Height; Width; Y and X.

Starting with the algorithm we make our first event. It'll become active if the Object "Destroyer" is on collison with the Object "Terrain. Additionally, the "Terrains" height has to be greater than 4 (Our XYZ-Value). You see the actions in the picture below and in the example file.

You see we call a function named "create", these functions are our second event. It creates our four objects at the four quarters of the original object and gives them their sizes.

At last but not at least, we make our third event. If the object "Destroyer" is on collision with the object "Terrain" and the Object "Terrain"s size is less or equal to four, the system destroys the object.

That's it!

If everything is right the object “Destroyer” will "erase" the ground. Run your projects and drag and drop the destroyer. The RedBall shows you that the physics work.

Hope you enjoyed my tutorial. If you still have questions, ask in the comments!

The Project:

.CAPX

tutorial-file.capx

Download now 188.83 KB
  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!