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

Get help using Construct 2

Post » Tue Apr 19, 2016 3:39 pm

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:

Image

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

Thanks!
Image
B
10
S
3
Posts: 35
Reputation: 781

Post » Wed Apr 20, 2016 4:58 pm

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.
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,273

Post » Thu Apr 21, 2016 7:24 pm

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. :)
Image
B
10
S
3
Posts: 35
Reputation: 781

Post » Thu Apr 21, 2016 8:12 pm

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
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,273

Post » Fri Apr 22, 2016 8:53 am

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:
Image

Thanks for your time trying to help me! :)
Image
B
10
S
3
Posts: 35
Reputation: 781


Return to How do I....?

Who is online

Users browsing this forum: alextro, Yahoo [Bot] and 6 guests