I have an unexpected delay in the game Mix_Chunk

So, I'm trying to learn SDL and create a little game. When the user presses the space bar, he should play a sound. It works, but the sound takes about 0.5 seconds to play ... How can I fix it? I checked the actual file to see if the delay was only part of it, and that turned out to be wrong.

SDL with C ++ in win vista.

Here is the code:

...
Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 )
...

    main() 
    {

    ...

    Mix_PlayMusic( BG_Music, 0 );   //background music

        while( quit == false )
        {
            fps.start();
            fire.handleInput( event, ship.get_x_pos() );
    ...
    }

handle input function:

void lasersC::handleInput( SDL_Event &event, int x )
{
    Uint8 *keystates = SDL_GetKeyState( NULL );

    if ( keystates[ SDLK_SPACE ] && delay == 0)
    {
        Mix_PlayChannel(-1, laser, 0);
        fired * F = new fired( NULL, S_HEIGHT - 50, x + 20 );

        F->shot  = lasers;
        F->y_pos = S_HEIGHT - 50;
        F->x_pos = x + 20;

        weps.push_back( F );
        delay = 10;
    }
}

If more is required, let me know.

+3
source share
1 answer

Usually when building SDL (apparently) DirectX headers are usually checked

Can you try recompiling DirectX support?

, ? .

EDIT - :

+5

Source: https://habr.com/ru/post/1710296/


All Articles