How do I check whether all instances are not on-screen?

Get help using Construct 2

Post » Mon Nov 28, 2016 4:16 pm

I'm making a game and I want audio to play when there is at least one instance of an object on-screen. If there isn't, I want to turn it off.

I've tried many things*, but currently I've resorted to making an instance variable 'OnScreen' and then, every tick, I make it so each instance either has 1 or 0, depending on whether they are on-screen. Then, I check whether an instance has 'OnScreen' = 1 and whether the sound isn't playing yet. If that's true, I play the sound.
To turn it off, I look up the nearest instance (to player) and whether it has 'OnScreen' = 0 and then I turn off the sound.

This works, but sometimes the closest instance isn't on screen, while a more further away instance is. There is no sound, even though I want there to be.

I would love it if there would be some way to check whether there is any instance on-screen. Thanks for any help in advance!

*I can't just simply check whether an instance is on-screen, because some are and some aren't. I want the sound to turn on even when not all are on screen, but at least one is.
B
2
Posts: 2
Reputation: 154

Post » Mon Nov 28, 2016 4:21 pm

Pick all instances, if on-screen add 1 to a global variable for each instance on screen. Check every tick. If global variable ever drops to 0 turn off the audio. Is how I would do it. There are a few ways though. Rather than add to a variable you could probably use picked count in the comparison as another way of doing it.
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Mon Nov 28, 2016 10:15 pm

I didn't realise there was a "pick all instances of an object" event. Why is it in system though? Shouldn't it be in the object category, for example as "pick by UID" is?

Anyway, I was inspired and looked more into logic and found a much easier way of doing it:
    Is "Object" on-screen \/
      Tag "Sound" isn't playing -> Play "Sound"
    Else -> Stop "Sound"


This seems to work. Thanks for the help anyway! :)
B
2
Posts: 2
Reputation: 154


Return to How do I....?

Who is online

Users browsing this forum: NN81 and 25 guests