我正在 SDL 2 中制作一个有声音的俄罗斯方块版本。我有背景音乐,效果很好。但是,声音效果(移动、旋转等)播放的是静态的,而不是它们应该播放的。
一些代码:
定义:
Mix_Music *music;
Mix_Chunk *move, *rotate, *clear, *difficult, *gameOver;
开头:
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 4, 2048) != 0) {
printf("Error: Failed to initiate Mixer subsystem. SDL_Mixer Error: %s\n", Mix_GetError());
return false;
}
music = Mix_LoadMUS("music.wav");
if (music == NULL) {
printf("Failed to load Music. SDL_Mixer Error: %s\n", Mix_GetError());
}
move = Mix_LoadWAV("move.wav");
if (move == NULL) {
printf("Failed to load sound \"move\". SDL_Mixer Error: %s\n", Mix_GetError());
}
rotate = Mix_LoadWAV("rotate.wav");
if (rotate == NULL) {
printf("Failed to load sound \"rotate\". SDL_Mixer Error: %s\n", Mix_GetError());
}
...
Mix_VolumeMusic((128 * options[0].currentOption * options[1].currentOption) / 10000); // (128 * 20 * 100) / 10000 = 25;
Mix_VolumeChunk(move, (128 * options[0].currentOption * options[2].currentOption) / 10000); // (128 * 20 * 100) / 10000 = 25;
Mix_VolumeChunk(rotate, (128 * options[0].currentOption * options[2].currentOption) / 10000); // (128 * 20 * 100) / 10000 = 25;
...
播放声音代码:
Mix_PlayChannel(-1, move, 0);
关:
Mix_FreeMusic(music);
music = NULL;
Mix_FreeChunk(move);
Mix_FreeChunk(rotate);
Mix_FreeChunk(clear);
Mix_FreeChunk(difficult);
Mix_FreeChunk(gameOver);
move = NULL;
rotate = NULL;
clear = NULL;
difficult = NULL;
gameOver = NULL;
Mix_Quit();
杂项信息:
- 在 VS 2013 中使用 C++
- 使用昨天下载的 SDL_mixer 2.0.0
- 声音约为 11kB,音乐为 94,675kB
- 声音在 Windows Media Player 中播放良好
如果您需要任何其他信息,请告诉我,并提前致谢!