BGM synchronize

Is there a way to put a flag in the background music and keep it in sync?
We would like to influence the game to match the rhythm of the music.

in Japanese.
BGMにフラグを入れて、同期を取る方法はありますか?
音楽のリズムに合わせて、ゲームに影響を与えたいと考えています。

I’m not sure I understand this question. Assuming you mean you want some event to happen at X timestamp of the music, just set a timer to run that event X time after you run the play function for the music. Or do you mean something else?

1 Like

This might have the answer you are looking for or the code to find the next question…

これには、探している答えや次の質問を見つけるためのコードが含まれている可能性があります。

Creating a steady rhythm for music-based game in XNA - Game Development Stack Exchange

EDIT

You could define your own flags and run that alongside the music.

独自のフラグを定義して、それを音楽と一緒に実行することもできます。

1 Like

Thanks for the reply!
I have been thinking about that too.
But I don’t think they are in perfect sync.
If the music is delayed in any way, it can cause misalignment.

Thanks for the reply!
I guess I still have to manage by the time.
public static MediaPlayer.TimeSpan PlayPosition { get; }
I found it and will try this!
日本語で書いてくれて嬉しいです!

2 Likes

If that doesn’t solve your issue, you can use the SoundEffect/SoundEffectInstance classes to play music. I’ve found it to be much less finicky and has features the Song class lacks. I believe this originally came about for me because one of our prototypes had 2 tracks that it needed to swap between at the same timestamp, so they’d be in sync but switch to the other track under certain conditions. I needed to use SoundEffectInstance to make that happen, if memory serves.

1 Like

Thanks for the reply!
I use MediaPlayer for BGM、I use SoundEffect(~Instance) for SE.
Certainly for BGM, I have never tried SoundEffect(~Instance),I will experiment!
I can also get the TimeSpan.