Jump to content

Playing Sound causes Frame Drop


Recommended Posts


I've noticed that switching between states or entering next state causes frame drop in my game.
First off all I need to say that I'm using Phaser.State in a little bit different way. I've split my game in multiple sections, like: IdleState, MovingState, AnimatingState, BonusGameState, etc....I was testing the game on my desktop PC, disabled practically all my code and also hidden all display objects. The only thing left in my game was testing the state switching, which resulted to be the main issue for the frame drop. It happens only twice, once you enter a new state. First frame drop (from 60FPS -> 20FPS) happens almost at the entering phase, and the 2nd happens always around 2.3s later. And this is super annoying especially because you can notice flicker in Moving & Animating state, even though we're talking here only about two occasions of frame drop per state.

I would like to know what could be the most expensive method/command inside StateManager -> clearCurrentState() and StateManager -> setCurrentState(key) ? I wouldn't like to break everything apart now, just because of this. Is there a way to optimize anything here?

Link to comment
Share on other sites

After a few hours of investigation, I found out that its not fault in State or Button class, but the actual frame drop happens once a sound effect is started and stopped.

My game always looses some FPS at those events. The game is using WebAudio and I'm playing sounds through mp3 audioSprite. Are there any possible solutions?

And my code for playing the sound effect is pretty bacis:

public static init(game: Phaser.Game) {
        this.game = game;

        let methodName: string = 'Audiosprites' + Config.getGameNameFull();
        this.audioSprite = this.game.add.audioSprite(Assets.Get.Audiosprites()[methodName].getName());


public static playSfx(marker: string): Phaser.Sound {

        let snd: Phaser.Sound = this.clickSnd;
        if (this.clickSnd === null) {
            snd = this.clickSnd = this.audioSprite.get(marker);

        if (snd) {

            snd.play(marker, 0, volume);

            return snd;

        return null;


Link to comment
Share on other sites

Solution to the problem was found, yeah :)
I've remembered from somewhere that someone mentioned, to be able to improve performance, if you have an active sound playing in loop all the time, with no content. So like playing a silenced track in loop.
In my case the silence track did not work, and I don't have a clue why. So I took some other sound track, set its volume to minimal (0.001), and played it in loop. And it worked, I don't get any frame drops anymore. But I still do not know what is the main reason for this. I also do not know why it also does not work if I'm playing empty track on 100% volume. But at least I now know in which direction I need to go.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...