[英]How can I immediately play a sound when another sound ends using XNA/XACT?
This question borders between the world of the audio designer and the programmer. 这个问题与音频设计师和程序员的世界接壤。 While this question might have to be partially answered by that domain of an audio designer, it is sure a problem for the programmer. 虽然这个问题可能必须由音频设计师的某个领域部分回答,但对于程序员来说肯定是个问题。 In our project, we want to loop a sound (background music) while the game timer is greater than one minute left. 在我们的项目中,我们想要在游戏计时器超过一分钟时循环播放声音(背景音乐)。 When this time is hit, we wish to stop the music as authored, and then immediately continue with ending segment . 当这个时间被击中时,我们希望停止播放音乐, 然后立即继续结束片段 。 I have been looking into XACT, and it seems to have support for different events. 我一直在研究XACT,它似乎支持不同的事件。 Unfortunately the documentation is lacking, and the application is somewhat alien to me as a programmer. 遗憾的是文档缺乏,作为程序员,应用程序对我来说有些陌生。
What I am looking to do is something along these lines (different approaches): 我希望做的是沿着这些方向(不同的方法):
The problem is that I haven't been able to find any mechanism to auto-play sound when another sound begins and that I can't find a way to hook up with the events made in the XACT project to C#. 问题是,当另一个声音开始时我无法找到任何自动播放声音的机制,而且我找不到将XACT项目中发生的事件与C#联系起来的方法。
If this can't be done (ie XACT/XNA lacks support for these operations), please gather your ideas on how to solve this problem with minimal cross-sound time errors. 如果无法做到这一点(即XACT / XNA缺乏对这些操作的支持),请收集有关如何以最小的交叉声音时间错误解决此问题的想法。 Preferably I would be able to control as much as possible of this in C# with calls to XNA. 我最好能够通过调用XNA在C#中尽可能多地控制它。
Here's how I did it. 这就是我做到的。
Close the window and test it by playing the Cue. 关闭窗口并通过播放Cue进行测试。 Also test to stop it As Authored to see if the behaviour fulfilles your expectations. 同时测试以阻止它作为Authored以查看行为是否满足您的期望。
In code, Stop the Cue As Authored to get this behaviour. 在代码中, 停止 Cue As Authored以获取此行为。 Immediate stops the cue without playing the sound outro. 立即停止提示而不播放声音outro。 I hope this helps other people who might run into this problem in the future. 我希望这可以帮助将来可能遇到这个问题的其他人。 The question and answer wasn't that much code oriented as I thought initially. 问题和答案并不是我最初想的那么多代码导向。 Also, this applies for XNA 2.0. 此外,这适用于XNA 2.0。 I don't know if there will be other options for controlling this kind of behaviour in XNA 3.0+. 我不知道在XNA 3.0+中是否还有其他控制此类行为的选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.