How do I stop a sound to be played after it was played once?

0 favourites
  • 3 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • Hi guys!

    I'm new, both to Construct and game development. I have a veeeery basic understanding of C# so I can see and understand a few things related to that on the events sheet. But I can't seem to be able to do what I want, tho.

    The thing is: I'm making a flappy bird like game, just for practice. I currently have 3 sounds: a flap sound that's played when the bird flaps, a point sound for when it passes through the pillars and a dead sound for when it collides with something. Is this last one I'm having trouble!

    The dead sound is played when: it collides with the upper pillar, it collides with the bottom pillar, it collides with the floor or when it is outside the layout ("collides with the ceiling").

    The thing is, when the bird collides with a pillar, is falls down to the ground and collides again with the floor, playing 2 times the dead sound. How can I deactivate this sound after it is played one time? I want to keep the dead sound when it collides with the floor, in case the flor happens to be the first collision.

    Help please! :)

  • You can use a variable as a condition to make sure it runs only once. You can press C on the event sheet to add a condition under the original event.

    So for simplicity, you create a global variable isDead set to 0 by default. Under the on collision with pillars event, you add a condition if isDead=0, then on the action side of the sheet where the 'play sound' action is, you would add 'set isDead to 1', therefore it is never true again and will not play the sound. Of course when you restart the game isDead is set to 0 again.

    Note because you are locking out the sound played, if you have other logic like animations that play when you collide with pillars they would have to be moved to a different event so it plays all the time.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks, plinkie. That helped!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)