Hi all,
In my program, which uses SDL, I have a SFX that runs every 4 seconds (roughly), whenever a ball hits a paddle. However, it is always about 0.5 seconds out of sync. The ball hits the paddle, bounces off it, then the music plays afterwards. It's not a huge gap, but it is easily noticeable and for me quite annoying.
This is the relevant code:
1 2 3 4 5 6 7 8
|
if (/*Checks for collision between ball and paddle*/) {
//Play the thunk sound:
Mix_PlayChannel(-1, thunk1, 0);
//Increments data about how many times the ball has been hit
bounces++;
//Creates the "Bounce" effect
yVel=(0-yVel);
}
|
Is there any way to speed up the playing of the sound? I've tried editing the silence from start of the sound using an audio editor, but it has made little difference. I think it's the overhead needed to call the
Mix_PlayChannel()
function that slows it down.
I've considered checking to see if the ball will hit the paddle if it continues on it's current trajectory, then plays the sound so the sound actually sounds closer to when the ball hits the paddle, but I would prefer not to use this method, as it might not calculate right.
Any suggestions are welcome,
hnefatl