How do I detect last sprite to leave the screen?

0 favourites
  • 12 posts
From the Asset Store
Show your master of martial arts by killing all flies empty handedly!!!
  • Hi, so I'm having some issues with audio playback.

    In my game, I've created a weather system.

    So far I have 3 states. Rain - Wind - Clear.

    Rain and Wind has turrets creating raindrops and leaf sprites that moves across the screen.

    I want a sound for each of these states, and I want them to fade into each other.

    Problem I have is that these sounds will have to trigger when last raindrop-sprite has left the screen, and whenever the last leaf has blown across the screen.

    It's not a problem getting them to play. (IsOnScreen -> TriggerOnce -> PlaySound)

    But it is a problem getting them to stop.

    I cannot have the sound stop when the weather variable changes, cause there's a lot of rain/wind sprites still on screen.

    So my question is. How do I detect last sprite (leaf or raindrop) leaving the screen?

  • Assuming they are destroyed when leaving the screen you have expression Object.Count, this is the number of them that exist. So you can start to trigger events when Leaf.Count=0 or Raindrop.Count=0

  • Thanks for the reply.

    Only thing is, that these sprites only get destroyed outside layout.

    Is there a way to use Object.Count for On-Screen objects only?

  • Leaf is on-screen || leaf.pickedcount

  • Still won't work.

    Would think there was an easy way to do this, but I can't find it..

  • Verified my solution worked before submitting it. Something is either input incorrectly or something else is getting it the way of that code. I’ll be happy to take a look at your code if you want to share it.

  • How does this look?

  • Got it working! This is what worked for me..

  • Whenever I work with Object.Count I use a Global

    Like such:

    If your way is working with no issues, then I see no problem with keeping it. If you bump into problems with it down the road you can try something out like this.

  • My method failed when player jumped and moved (Screen moved).

    Tried your suggestion but the wind audio just won't stop playing.

    This is driving me mad..

    To simulate my exact problem:

    Create one sprite with bullet behavior.

    Copy it multiple times across screen.

    Have some audio play when it is on screen.

    Have the audio stop when the last instance of that sprite leaves the screen.

    With one sprite (leaf), this works fine. The problem occurs when they're multiple.

    Thanks for helping me with this. :)

  • Works now. Seems the Leaves.Count doesn't get under 1.

    Hope this lasts, and thanks for all help and direction given, I appreciate it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 🤦 We are checking Leaf on-screen before making the count. So if no leaves are on screen we don't count. So when we have 1 leaf on screen we count 1, then it leaves and we stop counting leaving us with 1 :-p.

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