Animations cause game lag when scene is loading

Discussion in 'Technical Discussion' started by Christoph, Nov 13, 2015.

  1. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    I absolutely don't know why, but my character started to lag when changing scenes. It happens not with all scenes but always with the same scenes. And the weirdest part, where it happens, the scenes are short and not the most heaviest regarding elements, actions or animations in the game. It lags exactly at the position where the transparent character is placed in a new scene and just for half a second.

    Did someone experience something similar and could fix it?

    Update:
    First I thought it had to do with the y-position of the character but I move it around and nothing changed. Now I think it has to do with the jump animation: the characters jump animation is all over my 3 atlasses. Is there a way to get them all together in the first atlass? Even though thinking about it a little more, no reason why it should happen just with certain scenes. :(
     
    Last edited: Nov 14, 2015
  2. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    Ok... I couldnt find it out. It seems it has nothing to do with loading scenes or the characters in the atlasses. The log in Xcode tells me something I have no clue what it means. It appears exactly the moment the game lags:

    [PTPlayer] - Created motor at: 4048.244385 770.434998
    [PTPlayer] - Created motor at: 4048.244385 879.119019

    Anybody knows what that means?
     
  3. darren

    darren Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    134
    Likes Received:
    58
    interesting! do you have any wheels in that scene or links (possibly with speed)?
    [​IMG] [​IMG]
     
    Christoph likes this.
  4. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    No, definitely no wheels. I never knew how to use them. What is a link?
     
  5. darren

    darren Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    134
    Likes Received:
    58
    Christoph likes this.
  6. Florian Porkert

    Florian Porkert Boxer

    Joined:
    Sep 25, 2015
    Messages:
    22
    Likes Received:
    45
    Do you use a text label? If yes, please delete all text labels from Game Over, Main Menu and Game Field. Did it help?
     
    Christoph likes this.
  7. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    @Florian Porkert: Does the score amount and coin amount count? I also have the percentage sign at the loading screen. But in the particular scene there is no text label. Also no text (written text) label anywhere.

    @darren: yes, I have a lot of connections in every scene. Most are objects/platforms that move vertical and horizontal (some rotate) and are then connected to the coins/actions for example. But nothing special, at least not in the scene where it's happening. I have after this scene another one, much larger and with a lot of crazy stuff going on. But I repeat the almost same thing in level 2 (+ some more crazy stuff) and it's not happening there. But if it has to do with the next scene, can it be that a scene is already loading 1280 pixels before it actually appears? because if yes, then it would make more sense. Also because before I had this larger scene it didn't happen.
     
  8. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    I can answer this myself. I checked again and just before the motors get created the big scene is loaded:
    [PTPlayer] - add level section: 219605
    [PTPlayer] - Created motor at: 4048.244385 770.434998
    [PTPlayer] - Created motor at: 4048.244385 879.119019
    How can I understand/read the numbers? Are these coordinates? I suppose if I could understand at what place the motor is created I could understand what elements are causing the issue, right?

    Update:
    If this means 4048 x-axis and 770 y-axis, there is nothing there. :(
     
    Last edited: Nov 14, 2015
  9. darren

    darren Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    134
    Likes Received:
    58
    Perhaps 4048 is for 2000 pixels X-axis in scene 1 plus 2048 pixels X-axis in scene 2
     
    Christoph likes this.
  10. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    Thanks @darren for your help. It actually is the x-axis value from the beginning (start scene = 0). I now could identify the motor thing which actually was a bundle of two logics connected to a third logic. I deleted the connections and they are gone in the log.

    Unfortunately, the lag is not gone. It seems it's rather the add level section which causes the problem. Probably too much elements or the scene is too large (5120 pixels). Not sure what to do now. Most probably I will have to change the entire game structure, starting by making the scene smaller (my game is level based). This leads me to new questions I'll post in some other threads.

    Thanks again for all the help!
     
  11. Florian Porkert

    Florian Porkert Boxer

    Joined:
    Sep 25, 2015
    Messages:
    22
    Likes Received:
    45
    Try to remove all text labels that are not static. Like loading value, score, coins and so on. On all views like Game Over, Game Field, Main Menu and Loading. Did it help?
     
  12. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    I did also some other tests: for example I made the large level smaller from 5120 pixels to 4480 (maintaining the amount of elements more or less the same), but it didn't help. Then I tried with 3840, but still the same problem. With 3200 pixels it seems to have reduce a little but it still is there. The weird thing is, now with the smaller levels of 1280 pixels width, the short lag appeared too when loading the scene. Sometimes I have only as few as 6 platforms, 5 decorations and 8 actions (2 gameplays and 6 coins) in it. This makes me think again that the problem is not in the width nor the amount of elements used, but with something else.

    Thanks @Florian Porkert. I just tried by deleting all the text labels but unfortunately it does not make a difference either. Why do you think it should?
     
  13. darren

    darren Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    134
    Likes Received:
    58
    how many atlases?
    for your 8 actions, what sound effects are you using? how long are they? how large are the mp3 file sizes? if they are say 4 seconds, perhaps it's loading the sound into memory and the larger the sound the larger the lag.
     
    Christoph likes this.
  14. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    Sound FX are mostly under 1 second. I have an alarm that is 5 seconds. The music is 3 minutes 23 seconds long and loops. All audio is in 192kb so they are not big at all. Do you think the alarm is causing the issue? Will give it a try immediately.

    Regarding the atlasses, this is what I thought first. I had 4 with a lot of small elements. I reduced then some animations and have now a little under 3.
     
  15. darren

    darren Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    134
    Likes Received:
    58
    yes it's most likely the alarm :( - side note, music is background streamed and can be over two hours (i tested)

    all the atlases are loaded at launch so it's probably not the atlases, though, each atlas takes up memory so the more the add the more memory in general your app will use.

    you can try using your alarm at super super low quality to get the sound effect file size = to the 1 second ones and see if the lag goes away
     
    Christoph likes this.
  16. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    No it was not... :(
    I just deleted the alarm completely (118kb) from the game and removed unused sound objects. The lag is still there. I tried also with the background music but no change either.
     
  17. darren

    darren Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    134
    Likes Received:
    58
    are you using banner ads or frequent interstitials or more than one ad provider (versus just heyzap with mediation)? perhaps they are loading (and lagging)?
     
  18. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    I tested with ads on and ads off. When I have them on, the game lags even more but mostly at the beginning when starting the level. I tested with banners in the game itself and banners in the Game Over screen. I also have every 8 screens an interstitial (no video). I use Chartboost for the interstitials and iads for the banners. I additionally have a video reward button every 16 screens.

    Update:
    I just did a test deleting the entire large scene and the lag is gone. So it must be something I have there or the sum of all elements. I just did a test making the scene only 1920 pixels long and I still have the lag. I will play with the gameplay actions which I now suspect to be the culprits.
     
  19. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    Nope. The gameplay actions are not the culprits either. I deleted them all and am still experiencing the lag. This led me now to a complete debug session and it seems I finally have found the cause: animations!

    I have several animations in this scene. Not too much either, just about 5 different elements which get repeated. Each element has not more than 28 images looping and each image is between 100 bytes and 4kb. It seems when they are loading the first time the game lags. When I delete all objects with animations in the scene, the lag is gone. :(

    Does this have to do something with the use of memory or with the GPU? I ask because on newer devices there is no lag.

    @Andy: is this something I can fix? Is it possible that the distribution of the individual images between atlasses has something to do with it? I see that most animations are distributed over 2 or even all 3 atlasses I have.
     
    Forgive likes this.
  20. darren

    darren Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    134
    Likes Received:
    58
    the atlases are always in memory, so what might be loading into memory are elements that make up the scene like your 5 animations...if they each have 28 frames that might be equivalent to loading the [text coordinates of] 140 items for that scene.
     
    Christoph likes this.

Share This Page