All ahead warp factor 4

For questions about using Classic.

Post » Wed Feb 24, 2010 8:35 pm

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?
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Wed Feb 24, 2010 8:58 pm

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.
B
3
G
2
Posts: 27
Reputation: 729

Post » Wed Feb 24, 2010 9:15 pm

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



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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Feb 24, 2010 10:04 pm

@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
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Wed Feb 24, 2010 10:19 pm

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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Feb 24, 2010 11:25 pm

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 :wink:
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Thu Feb 25, 2010 2:27 am

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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Feb 25, 2010 3:03 am

"but also stop when I stop pressing the mouse button."
B
28
S
8
G
8
Posts: 530
Reputation: 7,154


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest