Located a problem causing lag, but how to fix it.?

app-etiteapp-etite Member Posts: 139
edited November -1 in Working with GS (Mac)
Hi guys.

In my game my character picks up objects off the ground. When I preview this on my device it hits a slight pause when the objects are picked up. In the objects actor I have behaviours....

when this and this is true... then...

destroy
Play sound
change attribute score
save attribute score

that must be to many things to do at once because if I turn off change attribute and save attribute off then there is no pause or lag when picking up the objects.

Ive tried a timer.. so for example after 0.5 seconds change attributes. But the timer doesn't work in this case.

I need the score to change, so how can I have all four behaviours executed without it lagging??

Thanks

www.twitter.com/appetitegames

https://www.facebook.com/pages/Appetite-Games/203583699676600

Comments

  • app-etiteapp-etite Member Posts: 139
    anybody?
  • FogelbergFogelberg Member Posts: 103
    Spawn and destroy actor is really costly and will give you a noticable lag. You should hide the actor instead (outside of visible area or/and set alpha to 0)
  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    Fogelberg said:
    Spawn and destroy actor is really costly and will give you a noticable lag. You should hide the actor instead (outside of visible area or/and set alpha to 0)

    This is very true when done in excess. And recycling actors in this manner is a great practice, it's best to move actors off screen instead of destroying them, especially if they are of a larger size.

    Maybe try changing the order in which it executes. Change the score first, then play sound, then interpolate actor off the screen, then save attribute.
  • app-etiteapp-etite Member Posts: 139
    thanks for the reply guys.

    Ive tried loads of different variations now.. and the only thing that works is if I turn off the score.. with that off its smoother than ice cream. destroy doesn't seem to be causing the problem.

    I do have custom fonts on my score.. but I followed tshirtbooths tutorials exactly so it should be ok.

    ggggrrrrr.. what now? :(
  • FogelbergFogelberg Member Posts: 103
    app-etite said:
    thanks for the reply guys.

    Ive tried loads of different variations now.. and the only thing that works is if I turn off the score.. with that off its smoother than ice cream. destroy doesn't seem to be causing the problem.

    I do have custom fonts on my score.. but I followed tshirtbooths tutorials exactly so it should be ok.

    ggggrrrrr.. what now? :(

    I would go through all your actors and try make the logic in them more effective, so they use less processor load. That could do wonders if you for example have 20 actors on screen at the moment and you managate to trim it down just a bit on each actor - then you've saved processor load x 20.

    Check the forum for tips on how you can make stuff more effective.
  • quantumsheepquantumsheep Member Posts: 8,188
    Have an actor that at the start of your level just plays every sound in that level, but at 0 volume.

    The UFO in Air Supply did the same thing till I tried this!

    Hope that helps!

    QS :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • FogelbergFogelberg Member Posts: 103
    quantumsheep said:
    Have an actor that at the start of your level just plays every sound in that level, but at 0 volume.

    The UFO in Air Supply did the same thing till I tried this!

    Hope that helps!

    QS :D

    Smart. :)
  • app-etiteapp-etite Member Posts: 139
    thanks guys.

    Quantumsheep, not sure I completely understand your method. so in this new actor, every sound in my game plays at the start of my level but with no volume, but can you explain why that would help with my lag issue?

    Thanks
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    because all the sounds will already be loaded in, it wont be loadign when the destroy happens
  • spliketspliket Member Posts: 93
    you may also want to try delaying the destroy actor behavior by 0.5 seconds or something. it can't do the other behaviors if the actor is destroyed too soon.

    if this conflicts with how the game should look (the item disappearing), you can add another change color (alpha) behavior and set the alpha to 0 while it completes the other actions/behaviors.
  • app-etiteapp-etite Member Posts: 139
    I have attached a video of the lag I get with my game.. the video runs very smooth so all the lag you see is 100% the games lag not the video quality. towards the end of the game I run out of actors so obviously the game start running smooth.

    like john suggested I have the sounds loaded in at 0 volume when the scene begins.

    When I collect the items on the floor I use alpha 0 not destroy.

    I have my scrolling actors laid out on a 2000 wide screen, is there a better way to do this or??? :(

    <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/tClVNlTeQ3g?hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/tClVNlTeQ3g?hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>
  • app-etiteapp-etite Member Posts: 139
    opps sorry

  • app-etiteapp-etite Member Posts: 139
    anyone?
Sign In or Register to comment.