How do I play a sound depending on which object is selected?

Just started using Construct 2? Post your questions here

Post » Thu May 14, 2015 12:40 pm

Hi.

First off, I'm a real beginner. I've read through a bunch of tutorials and articles and I've been playing around with the 'Creating a Memory Match Game' tutorial which was really great for learning but I'm getting stuck when trying to link objects with sound.

I'm trying to build a sound matching game for kids, where they get shown a collection of animals, a sound gets played and they have to click on the right animal. Each animal has a static image and a sound file. I've got it so that the game picks a random 4 animals from the collection and it picks a random one of these as the correct one, but then how do I play the correct sound file, without having an event for each animal?

I'm fine with basic audio, playing a sound as an action assigned to an event, but I can't work out how to do it conditionally, i.e. if the cow image is selected, then play the cow sound. It feels like it's a really simple thing to do but I'm just missing some basic bit of knowledge to get it working. If anyone can help me it'd be greatly appreciated.

Thanks,

James
B
4
Posts: 3
Reputation: 206

Post » Thu May 14, 2015 3:37 pm

well that's super easy @Distinction ,
basically lets say you have 12 animal pictures, right? now for the condition of the image selected so audio can play you have to do the on touch of if you want more advanced things you can do with booleans and trigger them as selected or stuff like that but for starters, the easy way now is

On touched object (cow) --------------------(/ or you can use tap also)
Audio>
> play sound cow no repeat
> tag"cow"

and so on for all the images :)


if you can add a capx i could help you out and fix it for you if you want :) and don't have disclosure problems
B
70
S
20
G
67
Posts: 1,315
Reputation: 42,303

Post » Thu May 14, 2015 3:44 pm

..or use Array to store audio file names..and only one Sprite for animals..

capx> http://s000.tinyupload.com/index.php?fi ... 2654540641
Image
B
64
S
23
G
7
Posts: 1,481
Reputation: 10,823

Post » Mon May 18, 2015 9:17 am

or
see this tut. maybe it will help
https://www.scirra.com/tutorials/1441/p ... ext-object
B
35
S
10
G
4
Posts: 250
Reputation: 7,908

Post » Mon May 18, 2015 9:22 am

Cheers all, I found the tutorial that korbaach's example must have been based on and managed to get it working using arrays. Thanks for your help :)
B
4
Posts: 3
Reputation: 206


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests