The Dink Network

Synchronizing sound with animation

August 9th 2007, 02:06 PM
bonca.gif
Christiaan
Bard They/Them Netherlands
Lazy bum 
I have a (maybe not quite so) advanced scripting question: Is it possible to "attach" a sound effect with a frame in an animation, for example, everytime frame 3 in an animation occurs, a sound effect plays?

As it is now, I'm working with wait commands, which is highly unideal. Any help?
August 9th 2007, 07:35 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
You know how the 'hit' sound of fists and sword is done? You could try to copy that. It involves setting SPECIAL frames in dink.ini, and sp_attack_hit_sound(&spritenum, &soundnum);

Now you just have to make it 'hit' something.

But beware: ALL sprites with that sequence will play that sound if there's something they 'hit' (i.e. when there's another hittable sprite in their hardbox).
August 10th 2007, 02:11 AM
sob_scorpy.gif
DinkDude95
Peasant He/Him Australia
The guy with the cute D-Mod. 
It seems quite easy. I may be wrong though.

Why don't you try looking at the frame delay for a sprite. Let's say it's 33 milliseconds and you want the sound to play on every 3rd frame. Then you would just type:

...
wait(99)
playsound(...);
wait(99)
playsound(...);

and continue that over and over. Or you could do something like this:

...
loop:
wait(99)
playsound(...);
wait(99)
playsound(...);
goto loop;

Is this what you wanted?
August 10th 2007, 09:06 AM
slimeb.gif
DaVince
Peasant He/Him Netherlands
Olde Time Dinkere 
"As it is now, I'm working with wait commands, which is highly unideal. Any help?"

"Why don't you try looking at the frame delay for a sprite. Let's say it's 33 milliseconds and you want the sound to play on every 3rd frame
...
wait(99)"

He does NOT want to use wait() commands, he wants to go AWAY from wait commands. Besides, this:
loop:
wait(99)
playsound(...);
goto loop;

would be enough if he did want that.
August 10th 2007, 09:45 AM
bonca.gif
Christiaan
Bard They/Them Netherlands
Lazy bum 
Thanks for the replies. I'm afraid your's doesn't work for me Magicman. I need this for a brain 6 script, so it's just a "static" sprite with a repeated animation.

It works using waits like Dinkdude says, but the waits differ from computer to computer, so on computer 1 it can be all good, but on computer 2 the sound is way off. When the cpu is under load, the sound can also delay.

So, any more ideas?
August 10th 2007, 07:07 PM
sob_scorpy.gif
DinkDude95
Peasant He/Him Australia
The guy with the cute D-Mod. 
Well, that's a pity. I don't think there's any way to do it other than the wait commands.

Anyway, if you do figure out some way to make it work, I'm guessing this is gonna be one good D-MOD!
August 10th 2007, 08:25 PM
bonca.gif
Christiaan
Bard They/Them Netherlands
Lazy bum 
No I'm pretty sure it is possible. And actually, the D-mod I'm making is going to be somewhat mediocre.
August 12th 2007, 06:48 AM
spike.gif
Since it's a static animation, you could do the whole thing manually, ie:

animate:
wait(50);
sp_pframe(&current_sprite,2);
wait(50);
sp_pframe(&current_sprite,3);
playsound(13,22050,0,&current_sprite,0);
wait(50);
sp_pframe(&current_sprite,4);
wait(50);
sp_pframe(&current_sprite,5);
wait(50);
sp_pframe(&current_sprite,1);
goto animate;
August 12th 2007, 08:22 PM
bonca.gif
Christiaan
Bard They/Them Netherlands
Lazy bum 
That was more along the lines I was thinking, thanks.

EDIT: had some rambling about it not working right, but that was due to my stupidness. I forgot to remove the brain 6. So yeah, it's working splendidly. A kazillion thanks peoples!

Everybody to the limit.
August 13th 2007, 09:21 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Oh, I thought that was actually the way you had it, with the wait commands and such

Anyway, great to see it works now