2 pictures with 2 songs

Get help using Construct 2

Post » Sun May 11, 2014 9:19 pm

I would like to creat an app if i touch 1. picture the 1. song is starting then if i touch picture 2 the first song stops and startin the 2. song...
How to do that?

Thanks!
B
4
Posts: 29
Reputation: 262

Post » Sun May 11, 2014 9:48 pm

Hi Valentin,

First you need to add the touch object and the audio object to one of your layouts, so that they can be used inside C2 (just like keyboard as well)

Then use something like this:
Condition: Double click on the touch object, and choose "on touched object ": choose picture1
Action: double click the audio object, and choose "Play" then choose the name of the audio file (song1 for example,) and give to it a tag, it can be any word, so that you can use the tag later instead of anything else (like, you can change the audio once later if you need, but wouldn't need to change in every event)

So what happens so far is that your first sound plays when you touch image1

Do the same for image2 and song2

Then, if you want a song to stop, you siply tell it to stop where you need it to be stopped:

You could use this:

Condition: On image1 touched:
Action:
stop song2
play song1

And in in another event:

Condition: On image2 touched:
Action:
stop song1
play song2

You should be fine with this, I hope I didn't forget anything! explore the tutorials section as well for more details.
B
19
S
4
G
3
Posts: 56
Reputation: 3,692

Post » Sun May 11, 2014 10:40 pm

There is it! :o
Thank you for your help! :P :mrgreen:

Bonus:
If i want to stop the song (1) when i touch the picute (1) one more time... how to do that?
B
4
Posts: 29
Reputation: 262

Post » Mon May 12, 2014 2:49 am

You could create an instance variable in the image sprite, by right clicking on it in the objects tab on the right, click on instance variables, then once the small popup opens: click on the "+" sign and type a name like: PlaySong1, give to it an initial value of 1

What you'd want to do is: if PlaySong1 = 1, then play song1
But if playsong1 = 0: do not play song1

You can create an interaction that would add 1 to the value of PlaySong1 whenever you touch image1
And then if PlaySong equals 2 then we reset it to 0

What you can do:
Create an event (by going to system, under General: compare two values) and it would say:

First value:
PlaySong1

is greater or equal

value: 2

Then action: double click on image1 object, set value (under Instance variables section), and give to it the value of 0

This will insure that whenever you touch image1, a value of 1 is added to its instance variable called PlaySong1

Now you have to create the events for playing/not playing the song1:

Condition: Touch object: on touched object, (choose image1)
then create two sub events: one for PlaySong1 = 0 and another for PlaySong1 = 1 (you don't need PlaySong1 = 2 since it is automatically reset to 0 if it reaches 2, as you would have made it earlier)

so while the condition of touched object is selected: add a sub event : either by right clicking and choosing subevent, or hit the B keyboard key

first sub event condition: double click the image1 object: compare instance variables (under instance variables section)
put a value of = 1

Then, action for the first sub event: double click the Audio object, and choose Play (and choose the song1 as you planned)

select again the main condition of the event, on touched object, and hit B again to create another sub event

this time you can copy the first sub event and paste it here, then edit the value from 1 to 0, or you can follow the same step for sub event 1 and just use a value of 0

then action for this value: double click the audio object, and choose "Stop" then choose the name of the file, in your case: song1

That's the basic I think, I hope I didn't forget anything obvious? Also remember to go to tutorials section and search for audio tutorials to learn with better examples.
B
19
S
4
G
3
Posts: 56
Reputation: 3,692

Post » Mon May 12, 2014 2:42 pm

Thank you for this!
But i got a problem.



"What you can do:
Create an event (by going to system, under General: compare two values) and it would say:

First value:
PlaySong1

is greater or equal

value: 2"


HERE i can't set first value to "PlaySong1" because it says: unknown expression, this is not system expression or variable name in this escope.

If i see right i can add here only value as numbers.
B
4
Posts: 29
Reputation: 262

Post » Mon May 12, 2014 3:13 pm

I started a new project and trying to make it works, that's why here is button and not picture.
Anyway it's working now this way:

Woeks.jpg


:o :D
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 29
Reputation: 262

Post » Mon May 12, 2014 9:18 pm

Oh sorry for confusion, glad it worked then :)
B
19
S
4
G
3
Posts: 56
Reputation: 3,692


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 17 guests