Simple audio for destructible items with health

1
GeorgeZaharia's avatar
GeorgeZaharia
  • 6 Jul, 2018
  • 906 words
  • ~4-6 mins
  • 1,332 visits
  • 0 favourites

In this entry we explain the audio playing on objects that are hit and destroyed, and also how we create a General Event sheet that has surtain global effects/actions in it so we don't have to copy paste the same code in all events for each level, and we just use 1 extra event sheet with all the events we want them to be globalize and by using the include function of Construct we call it in all levels that we need it those events to be called for.

In this example we only have 2 levels with their own event sheet and 1 General Destructible Audio Event sheet that we include in each level.

What do we need?

1 sprite and we draw a square in it make it what color you want, we add the physics effect on it, we set the Physics collision box to bounding box and checked the parameter is a bullet, since is a square and will fall, and place it on the layout and duplicate it a few times in the screen, i went a bit fancy and create a wood box in the Construct animation editor, but that is not important.

On the Box sprite we add a local variable and call it hp and give it a value of 6.

And additionally if we want to make it fade away instead of just quick dissapear when is HP = 0 we add the behavior Fade on it and set the timeout to 0.33 and un-check the Enable parameter so it doesn't destroy the box on start of layout.

1 tiledbackground give it the physics behavior and make it unmovable, since we don't want it to move, after that we place it in the layout at the bottom of the screen.

We also need the audio plugin and a few audio files for us to play when the box is hit or collides with other boxes.

And im going to use touch plugin so we can interact with the boxes and subtract some hp on each click on them.

We need to import 2 sound fx into our project sounds folder i picked Explode and SwingFX and i had a click effect but we can use SwingFx two times.

Now to be able to make multiple levels we name the layout in the right side from Layout to Level 1, and the EventSheet to ES_Level 1 .

If you are curious about how to place the objects in screen you can do something similar as the following image.

After doing all the above we move to the Event sheet now calles ES_Level 1 and add the following events.

And we should have something similar to the bellow image.

To create a 2nd level we duplicate the layout called Level 1 and also duplicate The event sheet ES_Level 1 and we name the duplicated layout to Level 2 and the duplicated event sheet to ES_Level 2

Now for the General Audio event sheet, we create one Event sheet and name it General Destructible Audio.

And on each ES_Level 1 and ES_Level 2 we right click and include event sheet and select "General Destructible Audio", if you have multiple general event sheet make sure this goes somewhere on top, or after the event sheet that you want to have priority. But since this is not a multiple general event sheet example, we just put the include on top of our events sheets like the image bellow.

Now on the Event sheet called General Destructible Audio we do the following Event

And you should have something like the bellow image

Now if we go to and preview Both level 1 and 2 the boxes will fall on the ground and when they collide with each other the 1st collision will sound a bit harder and the rest of the collisions will sound diffused.

Also when we touch each Box we will hear the swordSwing effect playing once, if we click it two more times the box will play the explode sound and start fade away.

And here we are at the end of another simple tutorial from which hopefully you learned a bit more then already knew.

If you got confused along the way you can download the file example from the bellow Download link.

For more tutorials like this leave a comment bellow, or follow this blog to get notified on my next post. Don't forget to like the post, which helps me know if the tutorial is good and should follow the same structure format or improve upon it.

"Box me" - Download

Subscribe

Get emailed when there are new posts!

  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Hi, I'm new to construct and was thinking about this the other day on how to achieve sounds effects. Thanks for taking the time to explaining it all in detail.

    Regards

    Deano