0 Favourites

How do I make some cars play the same sound?

  • The character limit makes it a bit hard to explain my problem in the topic heading.

    I'm making an endless-runnner with a car object that you run past from time to time. Basically I want each instance of the car to play a looping sound that starts when the car is first on-screen, becomes louder based on how close Car.x is to scrollx, and stops when the car is no longer on screen. The sound must also be muted and unmuted based on the local value 'sound'.

    I've given the Car object a boolean value called 'IsPlayingSound'. If the boolean value is false and the Car is on-screen and the local value 'sound' = 1, then the sound 'Car' is played looping with the tag "Car"&Car.uid.

    If the local value 'sound' = 0 (so that the player can mute the sound if it's annoying them) and 'IsPlayingSound' is true, then the boolean is set to false and the tag "Car"&Car.uid is stopped.

    If Car is not on-screen and 'IsPlayingSound' is true then set it to false and stop "Car"&Car.uid.

    And finally, if Car is on-screen and 'IsPlayingSound' is true then set the volume of "Car"&Car.uid to a little maths equation that makes it louder when Car.x is closer to scrollx.

    It all works surprisingly well, apart from when I try to stop the car sound if the local value 'sound' =0. The value can be toggled between 1 and 0 by pressing N so that the sound can be muted by the player.

    This works when one car is on-screen, however when more than one car is on-screen then only one of them has the sound stopped while the others continue to play.

    I'm sure that this shouldn't happen. If I've written If 'sound' = 0 and Car IsPlayingSound, then set IsPlayingSound to false and stop tag "Car"&Car.uid then surely it should affect every car? It should go through each car which 'isPlayingSound' one by one and set the boolean to false and stop the sound, right?

    I could easily solve this problem if sounds could have multiple tags. Every sound would have two tags, "Car"&Car.UID and just "Car". That way I could start, stop and control the volume of each sound using "Car"&Car.UID and I could mute/unmute every sound when the player presses N using "Car".

    Except I can't do that be because obviously Construct 2 doesn't support multiple audio tags. So, does anybody know an alternative solution?

  • If 'sound' = 0 and Car IsPlayingSound, and for each car.....then

  • What the fuck. How have I never noticed this 'for each' thing? This makes everything ever so much easier. Jesus christ.

  • Does 'for each' mean 'Repeat this action on every single instance of the object' or 'Repeat this action for every instance of the object that fits the conditions'?

  • it depends on the order of the events.. if you put a condition prior to the "for each", it will consider only the ones matching the previous conditions, not all the instances

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • it depends on the order of the events.. if you put a condition prior to the "for each", it will consider only the ones matching the previous conditions, not all the instances

  • Thanks for the help!

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