声音仍在另一帧中播放
Sounds still playing in another frame
嘿,我仍然听到一些不需要的声音效果仍在另一帧中播放,例如,当我单击鼠标左键(也是我的跳跃按钮)时,它会播放跳跃声音以及奇怪地播放收集硬币的声音即使我在进入游戏结束屏幕时从舞台上删除了每个 child。
现在我对声音通道有点陌生,所以如果需要使用它,请善待并解释:)
在第 1 帧中:
var myMusic1:Sound = new Game_Over_Noise();
var myMusic2:Sound = new Jump_Noise();
var myMusic3:Sound = new Coin_Noise();
var myMusic4:Sound = new Power_Up_Noise();
var myMusic5:Sound = new Theme();
var channel:SoundChannel = myMusic5.play();
第8帧,游戏画面:
function doJump(evt:MouseEvent):void
{
if(!isJumping) //If the player is jumping.
{
jumpPower = 30; //Jump power is equal to 30.
isJumping = true; //isJumping variable is also equal to true.
var channel:SoundChannel = myMusic2.play(); //Play sound effect.
}
}
function update(evt:Event):void
{
if(isJumping) //If the player is jumping.
{
MainChar.y -= jumpPower; //Subtract the value of jumpPower from the player's y co-ordinate.
jumpPower -= 2; //Decrease the value of jumppower by 2.
}
if(MainChar.y + gravity < ground) //If the value of the player's Y co-ordinate and gravity is less than ground.
MainChar.y += gravity; //Then add the value of gravity to the player's Y co-ordinates.
else //else
{
MainChar.y = ground; //The players Y co-ordinate is equal to ground.
isJumping = false; //Make isJumping equal to false.
}
}
第 5 帧,游戏结束画面:
SoundMixer.stopAll();
现在这停止了主题音乐而不是音效,现在我实际上不介意一直播放主题曲,但我希望所有音效(游戏声音)只在游戏中播放。
我知道我的编码不是最好的和高效的,但它对我来说很容易阅读,感谢您的帮助! :D
在我看来,您需要删除事件侦听器(即使在舞台外,它们也处于活动状态)。
嘿,我仍然听到一些不需要的声音效果仍在另一帧中播放,例如,当我单击鼠标左键(也是我的跳跃按钮)时,它会播放跳跃声音以及奇怪地播放收集硬币的声音即使我在进入游戏结束屏幕时从舞台上删除了每个 child。 现在我对声音通道有点陌生,所以如果需要使用它,请善待并解释:)
在第 1 帧中:
var myMusic1:Sound = new Game_Over_Noise();
var myMusic2:Sound = new Jump_Noise();
var myMusic3:Sound = new Coin_Noise();
var myMusic4:Sound = new Power_Up_Noise();
var myMusic5:Sound = new Theme();
var channel:SoundChannel = myMusic5.play();
第8帧,游戏画面:
function doJump(evt:MouseEvent):void
{
if(!isJumping) //If the player is jumping.
{
jumpPower = 30; //Jump power is equal to 30.
isJumping = true; //isJumping variable is also equal to true.
var channel:SoundChannel = myMusic2.play(); //Play sound effect.
}
}
function update(evt:Event):void
{
if(isJumping) //If the player is jumping.
{
MainChar.y -= jumpPower; //Subtract the value of jumpPower from the player's y co-ordinate.
jumpPower -= 2; //Decrease the value of jumppower by 2.
}
if(MainChar.y + gravity < ground) //If the value of the player's Y co-ordinate and gravity is less than ground.
MainChar.y += gravity; //Then add the value of gravity to the player's Y co-ordinates.
else //else
{
MainChar.y = ground; //The players Y co-ordinate is equal to ground.
isJumping = false; //Make isJumping equal to false.
}
}
第 5 帧,游戏结束画面:
SoundMixer.stopAll();
现在这停止了主题音乐而不是音效,现在我实际上不介意一直播放主题曲,但我希望所有音效(游戏声音)只在游戏中播放。
我知道我的编码不是最好的和高效的,但它对我来说很容易阅读,感谢您的帮助! :D
在我看来,您需要删除事件侦听器(即使在舞台外,它们也处于活动状态)。