作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在用 AS3 制作游戏。我想在每个背景中加入不同的音乐。
到目前为止,我已经成功地在玩家进入场景时开始播放音乐。但是如果他出去了,音乐还在播放……(我希望音乐在玩家离开场景时停止)。
我不明白为什么音乐还在播放。这是我的代码:
public function newBackground(thisBack:String):void{
var room = back.currentBack;
switch (thisBack){
case "maisonExt":
var mySound:Sound = new exterieur ();
mySound.play ();
最佳答案
您需要再次停止音乐。如果您不停止它,它将继续播放:)
当你调用 .play 时,它会返回一个 SoundChannel,它可以让你控制播放——改变位置、停止播放,以及访问让你控制音量的 SoundTransform。以下是一些示例代码:
public var currentSoundChannel:SoundChannel;
public function newBackground(thisBack:String):void
{
var room = back.currentBack;
if (currentSoundChannel != null)
{
currentSoundChannel.stop()
}
var nextSong:Sound;
switch (thisBack){
case "maisonExt":
nextSong = new exterieur ();
break;
}
currentSoundChannel = nextSong.play();
}
关于actionscript-3 - 如何在 AS3 中控制声音/音乐播放黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17132189/
我是一名优秀的程序员,十分优秀!