Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

xna - XNA Mediaplayer.Play()在不同时间开始在计算机上播放?(XNA Mediaplayer.Play() starts playing at different times across computers?)

I'm trying to develop a rhythm game in Monogame.

(我正在尝试在Monogame中开发节奏游戏。)

The notes are frame rate independent and work consistently over different computers, but the song playing does not.

(这些音符与帧速率无关,并且可以在不同的计算机上一致地工作,但是播放的歌曲不是。)

Right now I have it hooked up so the notes spawn and MediaPlayer.Play() do not start until I hit a key (so it's outside of loadcontent/initialize like I've seen other solutions suggest).

(现在,我已经将其连接起来,因此直到我按下某个键时,笔记spawn和MediaPlayer.Play()才开始(因此,它位于loadcontent / initialize之外,就像我看到的其他解决方案所建议的那样)。)

The song does not start playing until I hit the "I" key (gets checked in Update).

(在我按“ I”键(在Update中选中)之前,歌曲不会开始播放。)

However, the song seems to start playing at different times across different devices.

(但是,这首歌似乎在不同设备上的不同时间开始播放。)

I pull down the project on both my laptop (on battery) and desktop, and hit the "I" key at the same time on both, and I get different results on my laptop.

(我在笔记本电脑上(用电池)和台式机上都拉下了项目,同时在两者上都按了“ I”键,在笔记本电脑上得到了不同的结果。)

Sometimes it'll be seconds ahead of the desktop, other times it'll be a second or two behind (this is usually the case).

(有时它比桌面要早几秒钟,而其他时候则要落后一到两秒(通常是这种情况)。)

It seems pretty consistent on desktop.

(在桌面上似乎很一致。)

I'd try more than a dozen times and everything is still synced, but not on my laptop.

(我尝试了十几次,但一切仍然同步,但笔记本电脑上没有。)

I'm worried this is something that works only on my PC but not on others.

(我担心这只能在我的PC上运行,而不能在其他PC上运行。)

I've tried enabling fixedTimeStep and setting FPS to 60 (and setting the TargetElapsedTime to the window title ensuring that they are indeed both hitting 60) and I still get inconsistent results.

(我尝试启用fixedTimeStep并将FPS设置为60(并将TargetElapsedTime设置为窗口标题,以确保它们确实都达到60),但结果仍然不一致。)

I've read from other answers about using PlayPosition from the MediaPlayer class, but that property is readonly so I'm not quite how I could use that.

(我已经从MediaPlayer类中获得了有关使用PlayPosition的其他答案,但是该属性是只读的,因此我不太清楚该如何使用它。)

At first, I thought my notes were simply dependent on frame rate, but after setting FPS and fixedTimeStep, and also holding my laptop up to my desktop monitor they match up perfectly.

(起初,我认为我的笔记仅取决于帧速率,但是在设置FPS和fixedTimeStep之后,还将笔记本电脑放在台式机显示器上,它们完美匹配。)

It's just the song not syncing up.

(只是歌曲没有同步。)

I'm still a newbie to XNA but I couldn't find anyone else reporting different song starting timings like this.

(我仍然是XNA的新手,但找不到其他人报告这样的不同歌曲开始时间。)

Any help would be greatly appreciated.

(任何帮助将不胜感激。)

  ask by SyFySkyE translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I thought of a solution the second I got out of bed the next morning.

(我想到了一个解决方案, 第二我第二天就拿到床上出来。)

I figured there must be some overhead on MediaPlayer.Play(), but I wondered if I could start it, pause it, then resume instead.

(我认为MediaPlayer.Play()必须有一些开销,但是我想知道是否可以启动它,暂停它,然后恢复运行。)

Turns out, there is a Pause() and Resume() method which is what what missing from making this work.

(事实证明,有一个Pause()和Resume()方法是完成这项工作所缺少的。)

So!

(所以!)

If anyone else out there is having similar issues, here's what I did.

(如果外面有人遇到类似的问题,这就是我所做的。)

I kept a key to activate MediaPlayer.Play(), but immediately added MediaPlayer.Pause() after.

(我保留了激活MediaPlayer.Play()的键,但之后立即添加了MediaPlayer.Pause()。)

Then I got another key to resume the song, and the notes spawned when the song was resumed.

(然后我又得到了另一把琴键来恢复歌曲,恢复歌曲时便产生了音符。)

So pressing "I" played the song and paused it immediately.

(因此,按“ I”会播放歌曲并立即将其暂停。)

Pressing "R" resumed the song and started spawning the notes.

(按下“ R”将恢复歌曲并开始产生音符。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...