前提・実現したいこと
Dxlibraryで、ゲームを作っているのですが、
そのゲームのBGMとして曲をかけたいのですが、かかりません。
PlaySoundFile()では、動いてくれますが、PlaySoundMemで再生したいです。
発生している問題・エラーメッセージ
実行したときにエラーは出ませんが、音楽が流れません。
該当のソースコード
C
#include "DxLib.h" #include <string.h> #include <Windows.h> void DrawPos(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow); void DrawPic(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow, int x, int y, char*, bool); void DrawPic_k(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow, int x1, int y1, int x2, int y2, char*, bool); void DrawDialog(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow, int x, int y, const char*, char*, int Cr); //#define POS 1 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char BackGround[] = { "F:\Background\tanpopo.jpg" }; char NamePlate[] = { "F:\Background\name.png" }; char Name2[] = { "F:\Background\name2.png" }; char Mother[] = { "F:\Background\母.png" }; char yorunikakeru[] = { "E:\MUSIC\YOASOBI\THE BOOK\08 夜に駆ける.mp3" }; char gunjou[] = { "E:\MUSIC\YOASOBI\THE BOOK\06 群青.mp3" }; char kaikaikitan[] = { "kaikai.mp3" }; int Black = GetColor(255, 255, 255); //メモリへ読み込みサウンドハンドルを保存する。 int SHandle_yorunikakeru = LoadSoundMem(yorunikakeru); int SHandle_gunjou = LoadSoundMem(gunjou); int SHandle_kaikaikitan; SHandle_kaikaikitan= LoadSoundMem("kaikai.mp3"); SetGraphMode(1920, 1080, 32);//ディスプレイのモードを1920×1080にする。 SetTransColor(0, 0, 0);//白を透明にする。 if (DxLib_Init() == -1) { return -1; } SetMouseDispFlag(TRUE);//マウスのポインタを表示する。 DrawPic(hInstance, hPrevInstance, lpCmdLine, nCmdShow, 0, 0, BackGround, FALSE);//写真を表示。(x,y,BackGround,TRUE or FALSE) DrawPic_k(hInstance, hPrevInstance, lpCmdLine, nCmdShow, 1300, 400, 1652, 800, Mother, TRUE);//352*400 DrawPic_k(hInstance, hPrevInstance, lpCmdLine, nCmdShow, 0, 700, 1920, 1080, NamePlate, TRUE);//写真を表示(拡大縮小可能) //PlaySoundFile(kaikaikitan, DX_PLAYTYPE_BACK);//曲をかける。StopSoundFile();で止める。 PlaySoundMem(SHandle_kaikaikitan, DX_PLAYTYPE_BACK); SetFontSize(32); DrawString(30, 730, "主人公", Black); SetFontSize(16);//デフォルトに戻す。 DrawDialog(hInstance, hPrevInstance, lpCmdLine, nCmdShow, 30, 800, "主人公のセリフの表示", Name2, Black); #ifdef POS while (CheckHitKey(KEY_INPUT_RETURN) == 0)//エンターキーが押されるまで { DrawPos(hInstance, hPrevInstance, lpCmdLine, nCmdShow); } #endif ClearDrawScreen(); StopSoundFile(); WaitKey(); //サウンドハンドルの削除 DeleteSoundMem(SHandle_yorunikakeru); DeleteSoundMem(SHandle_gunjou); DeleteSoundMem(SHandle_kaikaikitan); DxLib_End(); return 0; }
試したこと
PlaySoundFile()では動きました。
サウンドハンドルを使うとできなくなります。
補足情報(FW/ツールのバージョンなど)
開発環境は、visual studio 2019 です。
まだ回答がついていません
会員登録して回答してみよう