0 Favourites

2 pictures with 2 songs

  • 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!

  • 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.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • There is it!

    Thank you for your help!

    Bonus:

    If i want to stop the song (1) when i touch the picute (1) one more time... how to do that?

  • 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.

  • 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.

  • 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:

    [attachment=0:2ukem4sk][/attachment:2ukem4sk]

  • Oh sorry for confusion, glad it worked then

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
76 9,273
Pandadoor's avatar
Pandadoor
Unread hot topic
0 Favourites
Place the picture in order Game
36 6,430
NECROKRIEG's avatar
NECROKRIEG
Topic
0 Favourites
The Most Unwanted Song
17 1,303
mumu64's avatar
mumu64