[SOLVED] How do I play sound at limits of sine cycle?

0 favourites
  • 4 posts
From the Asset Store
A set of board games to make your day joyful. Play, Enjoy, Relax
  • This is probably an easy fix, but I'm tired and my brain hurts:

    I'm trying to play a sound whenever any instance of an object reaches either the maximum or minimum of its sine behaviour.

    Currently I'm saving the cycle position to an instance variable "cycle" each tick and then testing every tick if cycle is less than 0.02; any less than 0.02 and the sample rarely plays, any more and it will trigger over successive frames, and even at this value it is temperamental, sometimes missing a play other times doubling up. I understand why that happens, but can't see a way around it.

    I also tried using "if object.cycle<0.02 trigger once | play sound" but this resulted in the sound playing once for each instance at the start (because they all start their cycles at 0) and then not playing again. I also swapped sine.cyclePosition for sine.Value but the problem is still the same.

    Thanks in advance for any help

  • The Sine extremes actually seem to occur at 0.25 and 0.75, so switch to two conditions:

    CyclePosition>0.25 & Trigger once -> sound

    Else CyclePosition>0.75 & Trigger once -> sound


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • blackhornet Thanks for the example, I hadn't considered that the extremes were at 0.25 and 0.75.

    This works great for a single instance, but how would you handle it with multiple instances at different cycle offsets? I can't get "trigger once" to repeat on objects, and using "compare two values" means that it fires for all instances every time one of them triggers the condition. If I had a fixed number of instances in the level then I could tie each of their cycle positions to a unique local variable, but if I'm spawning on the fly then using a local variable wouldn't work.

  • Managed to get it working for multiple instances with an extra instance variable:

    Cheers again for your help blackhornet - you pointed me in the right direction.

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