Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   SoundMixer.soundTransform отдельно музыка отдельно звуки? (http://www.flasher.ru/forum/showthread.php?t=204524)

Andrej 01.11.2013 19:14

SoundMixer.soundTransform отдельно музыка отдельно звуки?
 
Всем привет друзья.Во многих играх я видел в настройках громкость музыки настраевается отдельно а звуков отдельно.SoundTransform меняет звук глобально.
Вобщем собственно в заголовке и есть вопрос как можно менять громкость для звуков отдельно а для SoundChannel отдельно?Тут такой простенькой код для имзменения звуков,меняются конечно же громкость для всех звуков.

Код AS3:

var volumeControl:SoundTransform = new  SoundTransform(1);
var zvuktest:flash.media.SoundChannel;
var testsound:Sound = new testzvuk();
zvuktest = (new testsound()).play(0, int.MAX_VALUE);
function volplus(event:MouseEvent):void
{
volumeControl2.volume += 0.1;
SoundMixer.soundTransform=volumeControl;
testsound.play();
trace(volumeControl2.volume);
}
function volminus(event:MouseEvent):void
{
volumeControl2.volume -= 0.1;
SoundMixer.soundTransform=volumeControl;
testsound.play();
trace(volumeControl2.volume);
}
minusbtn.addEventListener(MouseEvent.CLICK,volminus);
plusbtn.addEventListener(MouseEvent.CLICK,volplus);

Спасибо.С уважением Андрей.

TWETTI 01.11.2013 19:34

У метода play класса Sound есть третий параметр SoundTransform.
Создайте два экземпляра класса SoundTransform. Один для настройки громкости музыки, а другой для громкости звуков. Настраивайте их свойство volume. Когда воспроизводите звуки, то указывайте третим параметром один SoundTransform, а когда музыку, то другой SoundTransform.

in4core 01.11.2013 19:34

не использовать глобальный сайнд трансоформ, а исползовать локальный.
channel.soundTransofrm ( помоему у канала, а может и у саунда, не помню)

Andrej 01.11.2013 21:48

Спасибо буду пробовать.Единственное ,как я уже проэксперементил для каждого звука нажо свой chanel.Много мороки.

in4core 02.11.2013 04:41

Andrej - нет не нужно.
Вот костылидзе вам для затравки

Код AS3:

package com.in4core.utils 
{
        import flash.events.Event;
        import flash.media.Sound;
        import flash.media.SoundChannel;
        import flash.media.SoundTransform;
        import flash.utils.Dictionary;
        import flash.utils.setTimeout;
        /**
        * ...
        * @author in4core progression lab
        */

        public final class FastSoundManager
        {
                private static const _hash:Dictionary = new Dictionary(true);
                private static const _playedHash:Dictionary = new Dictionary(true);
 
                private static var _locker:Boolean = false;
 
                public static function addSoundToLibrary(sound:Sound , soundName:String):void
                {
                        _hash[soundName] = sound;
                }
 
                public static function addSounds(array:Array /* every element is array as [sound , soundName]*/):void
                {
                        for (var i:int = 0; i < array.length; i++)
                        {
                                _hash[ array[i][1] ] = array[i][0];
                        }
                }
 
                public static function playSound(soundName:String ,
                loop:Boolean = false , volume:Number = 1 , delayedCall:Number = 0):void
                {
                        if (_locker) return;
 
                        setTimeout(playSoundDelay, delayedCall , soundName , loop , volume);
                }
 
                private static function playSoundDelay(soundName:String , loop:Boolean = false , volume:Number = 1):void
                {
                        if (volume === 0) return;
 
                        var transform:SoundTransform = new SoundTransform(volume);
                        var soundChannel:SoundChannel = new SoundChannel();
                        var sound:Sound = _hash[ soundName ];
 
                        if (!sound) return;
 
                        soundChannel = sound.play(0, 0, transform);
 
                        if (loop) soundChannel.addEventListener(Event.SOUND_COMPLETE , onSoundComplete);
 
                        _playedHash[soundName] = [ sound , transform , soundChannel ];
                }
 
                public static function stopSound(soundName:String):void
                {
                        if (!_playedHash[soundName]) return;
 
                        var soundChannel:SoundChannel = _playedHash[soundName][2];
 
 
                        soundChannel.removeEventListener(Event.SOUND_COMPLETE , onSoundComplete);
                        soundChannel.stop();
                }
 
                public static function stopAllSounds():void
                {
                        for (var i:* in _playedHash)
                        {
                                stopSound(i);
                        }
                }
 
                public static function stopAllSoundsInsteadOf(sounds:Array):void
                {
                        for (var i:* in _playedHash)
                        {
                                if(sounds.indexOf(i) == -1) stopSound(i);
                        }
                }
 
                public static function lockAllSounds():void
                {
                        _locker = true;
 
                        stopAllSounds();
                }
 
                public static function unlockSounds():void
                {
                        _locker = false;
                }
 
                private static function onSoundComplete(e:Event):void
                {
                        var soundChannel:SoundChannel = e.currentTarget as SoundChannel;
                        soundChannel.removeEventListener(Event.SOUND_COMPLETE , onSoundComplete);
 
                        for (var i:* in _playedHash)
                        {
                                if ( _playedHash[i][2] == soundChannel)
                                {
                                        playSound( i , true , soundChannel.soundTransform.volume);
                                        return;
                                }
                        }
                }
 
                public static function get isLocked():Boolean
                {
                        return _locker;
                }
        }
}


Andrej 02.11.2013 16:32

in4core ага биг респект.Ща ток посмотрю,что к чему :)


Часовой пояс GMT +4, время: 03:27.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.