A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Platform Game: Adding sound has added lag?

  1. #1
    Junior Member
    Join Date
    Sep 2008
    Posts
    9

    Platform Game: Adding sound has added lag?

    Hi.

    I've made a platform game in Flash using AS3.
    Game was fine, no lag, everything worked great.

    I imported some small .wav files for sound effects and added them using code like this:

    var s5:S5_enemy = new S5_enemy();
    var channel2:SoundChannel = s5.play();

    Sound effects occur on picking up items, jumping, killing an enemy, dieing, completeing a level etc.

    Now when playing the game I get lag (mostly in the screen scrolling) when a sound effect plays (like jumping for example) that I didn't get before.

    Does anyone know why this is, and if there is a way to fix it?

    Thanks.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Are you instantiating a new object each time you want to play it? You could keep the S5_enemy instance around, and just call play each time. That would eliminate the overhead of building a new object, which can be significant.

  3. #3
    Junior Member
    Join Date
    Sep 2008
    Posts
    9
    Yes I think I was.

    What I've done is moved all the var s5:S5_enemy = new S5_enemy lines to the beginning of the script, and left the calls to play the sounds where they are.

    But the lag is still present.

    Anyone explain the best way to do this?

    It is definately the sounds that are causing the problem, if I run in a straight line than scrolling is fine, aswell as it being fine for the first 5-10 seconds or so after loading the game and doing actions that cause sound.

    Then after that there will always be a small judder or stall in the scrolling if I make the character jump, or if I'm picking up items etc.

    I could just remove the sounds and it would go back to being fine, but they add alot to the game.

    Frustrating

  4. #4
    Junior Member
    Join Date
    Sep 2008
    Posts
    9
    Still looking for some help.

    Now also tried reducing the sound quality on export which also hasn't fixed the problem.


  5. #5
    Junior Member
    Join Date
    Sep 2008
    Posts
    9
    Now also tried changing sound type to mp3, still no change.

    I have a feeling it may have something to do with the way the main character moves.
    I used a template piece of code from an AS3 book, in which it uses creates movement time based instead of frame based, which theoretically is supposed to make the game perform better if the users pc can't handle the framerate.

    So I'm thinking that by adding sound it's somehow making the character judder slightly which in turn is making the background scroll (tied to characters x position) also judder.

    If this doesn't sound completely stupid (someone tell me) and I can post the character code. I'm still pretty new to AS3 so I'm not sure I know how I shoul rewrite it to make it frame based.

    Rarrgh.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center