2 registered members (Akow, tomaslolo),
1,536
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: How to preload sounds?
[Re: DJBMASTER]
#352373
01/03/11 10:17
01/03/11 10:17
|
Joined: Nov 2010
Posts: 96 Vienna
Schubido
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2010
Posts: 96
Vienna
|
I reproduced the behaviour in a short example. It uses "fisch1.mdl", "explo.wav", "explosin.wav", "explosion.wav" which I found in the 3DGS samples. It does a simple animation of the model (could be any model) and plays a sound if you press a number key (1-3). It turned out, that the delay is only the first time any sound is played, not for each sound. So it should not occur in the final version of the game, if a intro sound is played.
If you want to reproduce the effect, here is the code :
/////////////////////////////// #include <acknex.h> #include <default.c> #include <mtlFX.c> ///////////////////////////////
SOUND* Sound1 = "explo.wav"; SOUND* Sound2 = "explosin.wav"; SOUND* Sound3 = "explosion.wav";
// do some silly movements ... action AnimateFish() { var degree = 0; var movePercent = 0; while (1) { degree+=time_step*5; movePercent += time_step*30; me.x = 100*sin(degree); me.y = 100*cos(degree); me.pan = -degree; ent_animate(me,"",movePercent,ANM_CYCLE); wait(1); } }
function Sound() { while(1) { if (key_1) { snd_play(Sound1,50,0); } if (key_2) { snd_play(Sound2,50,0); } if (key_3) { snd_play(Sound3,50,0); } wait(1); } }
function main() { video_screen = 1; // full screen preload_mode = 3; // preload entities level_load(NULL); camera.x = -300; camera.z = 100; camera.tilt = -20; ent_create("fisch1.mdl", vector(0,0,0), AnimateFish); Sound(); }
|
|
|
Re: How to preload sounds?
[Re: Schubido]
#352374
01/03/11 11:23
01/03/11 11:23
|
Joined: Feb 2010
Posts: 320 TANA/Madagascar
3dgs_snake
Senior Member
|
Senior Member
Joined: Feb 2010
Posts: 320
TANA/Madagascar
|
Hi! I think that it's not a problem with the function. It is just that if the keys remain pressed, it will cause the sound to be played again and again until you release the keys. There are many solutions but one example is to wait for the release of a key to play the sound (or play the sound on key press and wait until the release of the key).
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
///////////////////////////////
#define PRAGMA_PATH "C:\\Program Files\\GStudio7\\templates\\sounds";
SOUND* Sound1 = "explo.wav";
SOUND* Sound2 = "explosin.wav";
SOUND* Sound3 = "explosion.wav";
// do some silly movements ...
action AnimateFish()
{
var degree = 0;
var movePercent = 0;
while (1)
{
degree+=time_step*5;
movePercent += time_step*30;
me.x = 100*sin(degree);
me.y = 100*cos(degree);
me.pan = -degree;
ent_animate(me,"",movePercent,ANM_CYCLE);
wait(1);
}
}
function Sound()
{
while(1)
{
// Play after a key was released
if (key_1)
{
while (key_1) {wait(1);}
snd_play(Sound1,50,0);
}
// Play on key press and wait until the key is released
if (key_2)
{
snd_play(Sound2,50,0);
while (key_2) {wait(1);}
}
if (key_3)
{
snd_play(Sound3,50,0);
}
wait(1);
}
}
function main()
{
//video_screen = 1; // full screen
preload_mode = 3; // preload entities
level_load(NULL);
camera.x = -300;
camera.z = 100;
camera.tilt = -20;
ent_create("fisch1.mdl", vector(0,0,0), AnimateFish);
Sound();
}
|
|
|
|