简体   繁体   English

当使用XNA / XACT结束另一个声音时,如何立即播放声音?

[英]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): 我希望做的是沿着这些方向(不同的方法):

  1. When the music stops, I want to tie an event to play another sound immediately 当音乐停止时,我想要将事件联系起来立即播放另一个声音
  2. When a marker is triggered in the music, I want to play another sound immediately 当音乐中触发标记时,我想立即播放另一个声音
  3. I would also like to know in my application when some of these events happen 我还想在我的应用程序中知道其中一些事件发生时

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#中尽可能多地控制它。

I think I've solved it now 我想我现在已经解决了

Here's how I did it. 这就是我做到的。

  1. Select the Cue which you want to change sound after it has been stopped in XACT . 选择在XACT中停止后要更改声音的Cue
  2. Set Playlist Type to Interactive . 播放列表类型设置为交互式
  3. Open Cue Transitions . 打开Cue 过渡
  4. Select View by Destination . 选择按目的地查看
  5. Select the Cue in the (stop) node visible in the tree view. 在树视图中可见的(停止)节点中选择Cue
  6. In Transition Properties at the right side of the tree view, for Source and Destination : 在树视图右侧的“ 转换属性”中,对于“ 源”和“目标”
    1. Set Source to End of Loop . Source设置为Loop of End
    2. Set Destiantion to Beginning . Destiantion设置为开始
  7. In Transition Properties at the right side of the tree view, for Transitions : 在树视图右侧的Transition Properties中,对于Transitions
    1. Set Transition Type to Direct Concurrent Transition . 转换类型设置为直接并发转换
    2. Set Transitional Sound to the sound you wish to play after the looping sound has completed its loop. 设置过渡声音你希望重复的声音后,播放声音已经完成了循环。

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以查看行为是否满足您的期望。


Implementation 履行

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM