Restart Button


#1

Hi there!
I’m using Zapworks Studio to create an animated Traking Image experience, with music. I have the 3D model with the animation and music in a scene that is working.
My next step is create a button from a PNG that restart both things (animation and music) when you press it.
I’ve read in https://docs.zap.works/studio/audio-and-video/filetype-support/ that I can loop the music by calling the restart() function on them when the finish event is fired.
My current script in the root (wich plays the music) is:
var myaudio = Z.Audio(“Song.ogg”);
myaudio.start();

I added the PNG button to the scene, then I right-click on it, and select> New>Script>PointerDown, and added the next script on it:
parent.on(“pointerdown”
var myaudio = Z.Audio(“Song.ogg”);
myaudio.restart();
}
Now the button is pressable, but it starts the song again while the first one is sounding yet, so the result is the song playing in 2 instances at the same time, what I need is stop the song and restart it, but I can’t find any command that makes the song end and restart.
I tried some commands also to make the animation restart when I press the button, but I didn´t find a solution.

Can you help me, please?
Thank you so much ^^


#2

You can use the z.audio() but like you found out when you use it in a new script it plays as new audio.
I like to just add the audio to the hierarchy so I can reference it easier.
Here is a sample code you can play with. It has a restart button and on finished code in it.
The on finished is left blank so you can do what you like with it. There is one for the model and one for the audio.

Audio Help.zpp (1.4 MB)

Tracking Image I used:

Steve