All ahead warp factor 4

This forum is currently in read-only mode.
  • My new game I have a thruster sound that I only want played while holding done my mouse (thruster) button. I want it to play and loop while holding the key but also stop when I stop pressing the mouse button.

    Is there an easy way to do that?

  • I'd love to hear what others do, but here is my horrible method:

    * Create a variable: "thrusterstart", set its value to 0.

    * While mouse button is down, add 1 to thrusterstart (it will continue adding '1' as long as the mouse is down, but that's ok)

    * When thrusterstart == 1, play sound with looping turned on

    * When mouse button release, set thrusterstart to 0.

    I had to do something similar in a test project. I'd love to know a simpler solution.

  • This will loop your sound while you hold down the mouse button:

    <img src="">

    The "NOT Channel 1 is playing" condition in event 3 will stop playing the channel after the current sound is finished. If you want it to stop immediately upon releasing the mouse button, you can just take that condition out.

  • deadeye:

    So if I have other wave sound effects should I assign them to different channels so they do not shut off too? Right now I am playing my 1 sound effect just Autoplay File AppPath & "Sound/ShieldHit.wav"

    Is that bad? I am such a noob with sounds and channels

  • Yes, for important sounds that you want more control over it's a good idea to load them in a channel. And it's also a good idea to reserve that channel so no other autoplayed sounds will choose it and interrupt your stuff.

  • This works GREAT! I never would have thought to do it like that.

    For anyone learning from this step three is wrong. It should be:

    Channel 1 is playing (without out the invert)

    I didn't have a cute channel graphic to show the code "grammar" mistake

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's not "wrong" if you want the last sound to finish before stopping

    And if you do want it to finish immediately upon releasing the mouse button, then just take the condition out entirely. Like I said before.

  • "but also stop when I stop pressing the mouse button."

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