【发布时间】:2018-09-30 12:18:18
【问题描述】:
我制作了一个纸牌游戏,它使用运行良好的 foreach 循环从 UI 中的资源中获取并显示玩家卡片。我最近还添加了卡片声音,以便在 UI 中显示每个图像之前播放声音。但是,总是先播放声音,然后显示图像。有点烦……
我使用声音播放器和 playsync()。如何强制 GUI 更新? (在声音之间)
这里是一些代码...
开头
//loop
foreach (var player in playerGUIs)....
//Call the sound Card_Sound(); //See below
//Update image player.img1.Source = new BitmapImage(new
Uri(("/Utilities;Component/Resources/" + card_file + ".png"),
UriKind.Relative));
private void Card_Sound()
{ //Play sound System.Threading.Thread.Sleep(800); // First sleep 800 milliseconds
using (FileStream stream = File.Open(@"Resources\dealingcard.wav",
FileMode.Open)) {
SoundPlayer myNewSound = new SoundPlayer(stream);
myNewSound.Load();
myNewSound.PlaySync(); }
}
【问题讨论】:
-
发布代码时遇到问题....呃,为什么这看起来如此困难....希望它是可读的...