Phaser Audio Delay

이것은 나에게 여러 번 일어났습니다. 다시 Phaser 오디오 딜레이에 직면 해 있습니다! 나는 준비가되어있다. 예술 자산이 들어가고 점수 판이 작동하며 내일 게임을 시작해야합니다! 빨리 배경 음악을 넣고 반복하십시오. 게임은 시작되지만 음악은 어디에 있습니까 ???

3 초 기다려 ...

거기는! 그것은 성가신 지연이지만 우리는 그것을 무시하기 위해 시작해야합니다. 그 밖의 무엇을 할 수 있습니까?

이제 마감 기한을 넘기지 않고 다시 물러나서 무슨 일이 일어나는지 살펴 보겠습니다. 나는 왜 음악을 미리 불러 들여서 지연시킬까요?

나는 당신에게 문제를 보여주기 위해 표본을 모았다. 다음은 일반적으로 음악을로드하는 코드입니다. 이미지가 정상 속도로로드되는 것을 볼 수 있도록 이미지를 배치합니다. 또한 타이머가 포함되어 있으므로 지연되기 전에 몇 초가 지나야하는지 확인할 수 있습니다.
sdsd
var StateMain = {
    preload: function() {
        game.load.audio("music", "audio/music.mp3");
        game.load.image("title", "images/Cool-Game-Title.png");
    },
    create: function() {
        this.secs = 0;
        //create the music
        var music = game.add.audio("music");
        //play the music
        music.play();
        //
        //
        //
        //put the title on screen
        var title = game.add.image(game.width / 2, game.height / 2, "title");
        title.anchor.set(0.5, 0.5);
        //make the timer text
        this.timeText = game.add.text(game.width / 2, 100, "0",{fill:'#ffffff'});
        this.timeText.anchor.set(0.5, 0.5);
        //start counting seconds
        game.time.events.loop(Phaser.Timer.SECOND, this.tick, this);
    },
    tick: function() {
     this.secs++;
        this.timeText.text = this.secs;
    },
    update: function() {}
}
그럼 여기서 뭐하는거야? 어쨌든이 Phaser 오디오 지연의 원인은 무엇입니까? 미리로드 된 경우에도 재생하는 데 몇 초가 걸리는 이유는 무엇입니까? 음, 나는이 게시물에서 오디오가 디코딩되어야 할뿐만 아니라로드 될 필요가 있음을 지적하는 몇 가지 해답을 발견했습니다. 브라우저가 재생되기를 기다리는 동안 브라우저가 수행하는 작업입니다.

Phaser는 음악 파일이 디코딩되었는지 여부를 감지 할 수 있습니다.
game.cache.isSoundDecoded('music');

이 함수는 진실 또는 거짓을 돌려 줄 것입니다. 따라서 우리가 사용할 수있는 솔루션은 stateLoad라는 별도의 상태에서 모든 것을 로드하는 것입니다.
사전로드가 완료되면 업데이트 기능을 사용하여 음악이 디코딩되었는지 확인합니다.
그렇다면 상태를 stateMain으로 전환합니다. 사용자가 게임을 시작한 후보다 로딩 화면에서 기다리는 것이 게임 업계에서 잘 받아 들여지고 있습니다.
일반적으로 로딩 화면에는로드 바 또는 일부 메시지가 포함되지만 기술적 인 예에서는 충분합니다.

var StateLoad = {
        preload: function() {
            game.load.audio("music", "audio/music.mp3");
            game.load.image("title", "images/Cool-Game-Title.png");
        },
        create: function() {
         //only fires after preload is done
            var statText = game.add.text(game.width / 2, 100, "Decoding....", {
                fill: '#ffffff'
            });
            statText.anchor.set(.5, .5);
        },
        update: function() {
         //check to see if the audio is decoded
            if (game.cache.isSoundDecoded('music')) {
                    game.state.start("StateMain");
                }
            }
        }
var StateMain = {
    preload: function() {
       //moved loading here to stateLoad
    },
    create: function() {
        this.secs = 0;
        //create the music
        var music = game.add.audio("music");
        //play the music
        music.play();
        //
        //
        //
        //put the title on screen
        var title = game.add.image(game.width / 2, game.height / 2, "title");
        title.anchor.set(0.5, 0.5);
        //make the timer text
        this.timeText = game.add.text(game.width / 2, 100, "0",{fill:'#ffffff'});
        this.timeText.anchor.set(0.5, 0.5);
        //start counting seconds
        game.time.events.loop(Phaser.Timer.SECOND, this.tick, this);
    },
    tick: function() {
     this.secs++;
        this.timeText.text = this.secs;
    },
    update: function() {}
}

결과는 다를 수 있지만 내 로컬 호스트에서 음악은 두 번째 테스트에서는 0으로, 첫 번째 테스트에서는 약 3에서 재생됩니다.

댓글 없음:

댓글 쓰기