How do I play sound on a spesific moment

Just started using Construct 2? Post your questions here

Post » Wed Jul 22, 2015 12:34 pm

I got caught on a silly audio problem which im sure is laughably easy to remedy. Im trying to get the enemy AI grunt when he is hit by a bullet. Easy enough.. thing is, id like to play a different audio if he dies as i have a random value that deducts his energy to simulate that he can be either wounded or killed. For now he's just grunting even if he's killed.
B
7
S
1
Posts: 93
Reputation: 632

Post » Wed Jul 22, 2015 9:16 pm

give the enemy an instance variable. So if alive grunt if dead scream or whatever you have :P Or compare health. Greater than 0 = grunt and if zero play kill sound

So on bullet collision with enemy
subevent
if alive > play grunt
if dead > play scream
B
58
S
24
G
14
Posts: 775
Reputation: 13,166

Post » Thu Jul 23, 2015 12:00 pm

Oh, i got it almost to work. I was overthinking it. Got it to play both sounds by doing an "on destroyed- play sound.."
However, trying to finetune this a bit since the enemy can get a fatal shot from the first bullet, id like it to not give out the grunt which it now makes and also the falling to ground sound which i have set p as a dying sound. I dont know how to make the code work for me like that.

https ://dl.dropboxusercontent.com/u/73502848/enemydeadcode.png
B
7
S
1
Posts: 93
Reputation: 632

Post » Thu Jul 23, 2015 12:33 pm

Ok, then you have to setup so the grunt only plays when the enemy is not dead. So if you have different animations for that you can make the sound trigger on the correct animtaion like this:

Live Demo
https://dl.dropboxusercontent.com/u/100 ... index.html

CapX
https://dl.dropboxusercontent.com/u/100 ... sound.capx

This is maybe not exactly how you would do in your project but the concept is the same and you should be able to get it to work with the correct triggers and conditions.
B
58
S
24
G
14
Posts: 775
Reputation: 13,166

Post » Thu Jul 23, 2015 12:51 pm

Juicy wrote: Image


Image
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Thu Jul 23, 2015 3:11 pm

korbaach, thanks. But still cant get it to work with that. It starts playing the eeh sound in a kazillion times per second. I don't get it why it does that.

Thanks Anonnymitet, that might do the trick. I haven't done any death animations yet but i have a strong feeling this is the way to go.
B
7
S
1
Posts: 93
Reputation: 632

Post » Thu Jul 23, 2015 3:29 pm

example.capx

One Event and Two Sub-Events...

Image
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sat Jul 25, 2015 2:19 pm

Okay, i tried it again your way korbaach and got it to work. I have no idea what was wrong since i just did it exactly the same way as before. Seems like sometimes starting from the beginnig on a clean slate helps :) Thanks to both of you!
B
7
S
1
Posts: 93
Reputation: 632


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests