How do I play audio if any of the same object is on screen

0 favourites
  • 5 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hi!

    I've been trying to figure out how to play an audio file if any of the same object is on screen. Then if none is on screen, the sound needs to stop.

    For example, this doesn't work:

    Does any one have a good example of how I can make this work?

    Thanks!

  • That should gave worked but you could try creating a transparent sprite with no image and size it to cover (call it cover) the entire screen and use:

    Cover> is on overlap with Wasp> Play buzzing

    Cover> (x)is on overlap with Wasp> Stop buzzing

    One reason your above example may not be working is if the parallax setting for the layer the Wasp is on is different, giving a coordinate that reflects being on screen.

  • Hi!

    Well what happens is, the sound only plays when all wasps are on screen. It doesn't work if only some is visible, or only one for example.

    Have been trying to tweak it any way I can, but it hasn't worked so far. Not sure if I'd like to overlay a empty sprite for this, but might resort to it if it works and if there's no other solution.

    The layer the Wasps are on, have default parallax.

  • That's because you have a conflict with the code if you have wasps off screen and on screen at the same time. The code runs from top to bottom and "Wasp > (x)Is OnScreen> Stop buzzing is triggered last.

    Try switching the order and place -- "Wasp > (x)Is OnScreen> Stop buzzing -- on top. That should work.

    Otherwise I think the solution I laid out will work fine and wont cause any performance issues. I've used it before.

    Good Luck

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I got it to work finally.

    Just as I was about to test your method, I realized I think you misunderstood the "is on screen" event. I'm not actually trying to test if any wasps are on the layout, only if they are in the visible area of the screen, which is what "is on screen" checks for.

    Here's what I ended up doing that's working now:

    Thanks for your time trying to help me!

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