Removing Lag from LOK

A place for tutorials on how to get the most out of Flash

Removing Lag from LOK

Postby IrrelevantComment » Sun Apr 22, 2012 11:08 pm

When developing locally in AS3, LoK lags like hell and it took me a while to work out why. Turns out that repeated calls to gotoAndPlay() can cause a huge memory leak if the object is running code in the nested frames. For example, I called gotoAndStop() about 50 times on a Krytal template and my frame rate halved. I then went back and changed it so that the armour and cum symbols were not looping and repeated the experiment: no frame rate loss. So basically if you have a memory leak you cant account for, remove code from symbols that are nested deeply as they stop the object from being garbage collected.
IrrelevantComment
 
Joined: Tue Mar 15, 2011 7:46 pm

Re: Removing Lag from LOK

Postby dirtyc101 » Thu Apr 26, 2012 3:19 am

Good tip. Thanks
-DirtyC101
dirtyc101
 
Joined: Fri May 21, 2010 10:18 pm

Re: Removing Lag from LOK

Postby GoRepeat » Thu Apr 26, 2012 9:58 pm

Wow great call, I rearranged some internal symbols to use stop/object commands instead of play loops and there was a pretty noticeable difference
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Removing Lag from LOK

Postby The Illusive Man » Mon May 28, 2012 3:57 am

If I may, I'll be voice for newbie flash animators/programers and ask the question: What commands would serve as the most effective replacements for gotoAndPlay loops?

Humanity First

- T.I.M.
"Beware that, when fighting monsters, you yourself do not become a monster... for when you gaze long into the abyss. The abyss gazes also into you."
User avatar
The Illusive Man
 
Joined: Wed Apr 25, 2012 5:12 pm
Location: Undisclosed Location

Re: Removing Lag from LOK

Postby OwnerOfSuccuby » Mon May 28, 2012 9:15 pm

I do not see any lags in LoK on my computer. I think it is all good with it (but some problems on android platform).

But yes - when you use cycle it eats ypur computer perfomancy. For the PC it all is okey - you will see no defference. For platforms with weak processor the structure that you will use must be different. So i little trully do not understand what is it for ?

For example if you will do lok for mobile device i think it have to change some vector animation on pictures - it works faster some times (but some times it eats more memory).

GoToAndStop/Play loops - may be changed on direct command from root layer. For example you have got fox - you say all her parts go to and stop to so,e weapon frames - and then when they are in use they will not change unless you say them to change. If some parts leave for one frame you have to say it change again - or make some var in root layerfor example. On the first enter in that movie clip that movie clip read that var and go to that frame. When that frame is active - it will not change or eat your PC perfomancy - it need no loop - but if you change some thing you have to change it by function again.

It is anither way to load it from storage file not go to and play - and some times may be it is even better, but i really do not understand what is it for ? If you will use more then 1 character than yes - it will lug - but now i think LoK2 works OK on my computer.

Or may be i do not understand what are you talking about ? Sorry i am not good in english :roll:
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Removing Lag from LOK

Postby IrrelevantComment » Tue Jun 05, 2012 8:44 pm

The Illusive Man Wrote:If I may, I'll be voice for newbie flash animators/programers and ask the question: What commands would serve as the most effective replacements for gotoAndPlay loops?


add/removeEventListener can be used, depending on the situation.

In this situation however, there were three armour settings, and 2 frames for each. The game looped over a set of two frames and on the second frame checked which armour was being worn, and then started a loop of the two frames containing that armour (if that makes sense).

My solution was to put each armour on a seperate frame, and then add a function something like this:
Code: Select All Code
function SetArmour(s : string)
{
     switch s
          case "armour1": armour.gotoAndStop(1); break;
          case "armour2": armour.gotoAndStop(2); break;
          case "armour3": armour.gotoAndStop(3); break;
}


Basically in many cases you can replace small loops (where there is no animation) with a function that sets the frame only when necessary.

OwnerOfSuccuby Wrote: but i really do not understand what is it for ? :


It solves a problem with Flash's garbage collection. Basically, when you create objects in Flash, they take up memory even when they are removed from stage, so every time you leave the screen in LoK, another huge chunk of data is created. Normally Flash would remove the old data which is not being used, but as I discovered, it will not remove it if small parts of the data chunk are still running animations.
IrrelevantComment
 
Joined: Tue Mar 15, 2011 7:46 pm

Re: Removing Lag from LOK

Postby BlueLight » Tue Jun 05, 2012 9:17 pm

In java i believe how garbage collection works is if you have a reference variable connected to a object, then it wont be deleted.
Basically if you can use the object then it wont be deleted.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Removing Lag from LOK

Postby OwnerOfSuccuby » Tue Jun 05, 2012 11:01 pm

IrrelevantComment Wrote:
The Illusive Man Wrote:If I may, I'll be voice for newbie flash animators/programers and ask the question: What commands would serve as the most effective replacements for gotoAndPlay loops?


add/removeEventListener can be used, depending on the situation.

In this situation however, there were three armour settings, and 2 frames for each. The game looped over a set of two frames and on the second frame checked which armour was being worn, and then started a loop of the two frames containing that armour (if that makes sense).

My solution was to put each armour on a seperate frame, and then add a function something like this:
Code: Select All Code
function SetArmour(s : string)
{
     switch s
          case "armour1": armour.gotoAndStop(1); break;
          case "armour2": armour.gotoAndStop(2); break;
          case "armour3": armour.gotoAndStop(3); break;
}


Basically in many cases you can replace small loops (where there is no animation) with a function that sets the frame only when necessary.

OwnerOfSuccuby Wrote: but i really do not understand what is it for ? :


It solves a problem with Flash's garbage collection. Basically, when you create objects in Flash, they take up memory even when they are removed from stage, so every time you leave the screen in LoK, another huge chunk of data is created. Normally Flash would remove the old data which is not being used, but as I discovered, it will not remove it if small parts of the data chunk are still running animations.


Yes - it is theory. But if all works good - for what is it for ? :lol:

But yes if all this will be removed LoK will work on mobile devices without lugs may be. But some stages have very heavy vector animation i think. But it is not designed for it now - so for that purpose it have to be remake a little.

On normal PC it does not lug at all.

So i do not see real reason to make it now - may be i am wrong - but it is more better to make full complicated game with what we have now - it is open source so it can be easily remade in future in some thing you need.

But yes to use gotoandplay - is bad solution in armor - i know it. I do not use it and use GoToAndStop functions too (Or load parts from another files). But it is not hard to remake in any time so i think it is not the main problem now ;) .
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Removing Lag from LOK

Postby diablopop » Fri Aug 03, 2012 10:51 am

I want to say press release is the best medium for promoting a new business or any news or products launched by a company or firm.It is a great medium of getting the traffic on a website.If i forget some points about press release please share your views.





_____________________________________________________
Diablo iii items
D3 Gold
diablopop
Newly Registered
 
Joined: Fri Aug 03, 2012 10:47 am

Re: Removing Lag from LOK

Postby OwnerOfSuccuby » Fri Aug 03, 2012 5:05 pm

I was mistaken. When i start remake LoK, i find that it trully lags like hell !!! :lol:

I thought it were mistakes in code, but the most ptoblem is it's animation i think. When you move a lot of heavy objects you get lags. For example sex movies in it. If you make the best quality - and put a lot of animation of krystal get fucked - you will get a lot of lags, even if you remove all the code from it.

It is possible to remove but you will get some new problems. Bigger size of flash - if you will try to remove some components to movie for example.

If you make quality to low - you have less lags, it means that the main problem is in animation AND !!! models !!!

It looks like the models are too heavy for vector animation, were it traced from image or made in some other programs (not in flash) ?

In my other project i use very heavy code and another animation and it do not lag (or just a little). When i try to use models from LoK i get lags - i think the part of problem is in lizard models and there animation, that they make lags, but may be i am wrong - it is only my opinion. But i did not find another reason for what i wright, may be some another problems too.


By the way, BlueLight = cool new avatar picture :lol: :mrgreen:
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Removing Lag from LOK

Postby Biles » Thu Oct 11, 2012 5:29 am

There's also the consideration on the number of anchor points too. The more you have, the more it will lag.
Need some basic Flash character animations? Then stop by at:
Biles' Animation Kit

Current RPs:
n/a
User avatar
Biles
 
Joined: Sun Apr 03, 2011 4:53 am

Re: Removing Lag from LOK

Postby OwnerOfSuccuby » Fri Oct 12, 2012 4:31 pm

"I currently use Flash CS5.5, when using the oval or circle tools, is there a way to force Flash to use only 4 anchor points to draw out the shapes instead of the standard 8?"

may be some trace solution ? I mean exchange part that drawing your object using your processor to some static objects like image or etc ?

"There's also the consideration on the number of anchor points too. The more you have, the more it will lag."

Yes - than more objects you use and than mre of them plays and than more of them are in size = more lags.

If you are not limited in spase - you can ty to make it more size but remove all calculation from it. Make all that is possible like static movie - animated like in old time cartoons by static frames without moving objects (trace them).

I think you will have less lags but size of your movie will be bigger.
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Removing Lag from LOK

Postby Exist » Sat Mar 30, 2013 4:04 am

IrrelevantComment Wrote:When developing locally in AS3, LoK lags like hell and it took me a while to work out why. Turns out that repeated calls to gotoAndPlay() can cause a huge memory leak if the object is running code in the nested frames. For example, I called gotoAndStop() about 50 times on a Krytal template and my frame rate halved. I then went back and changed it so that the armour and cum symbols were not looping and repeated the experiment: no frame rate loss. So basically if you have a memory leak you cant account for, remove code from symbols that are nested deeply as they stop the object from being garbage collected.


There actually used to be a bug in flash were if you made a two frame animation and in the 2nd frame you have gotoAndPlay(1); if would force Flash to crash.
User avatar
Exist
 
Joined: Thu May 12, 2011 7:57 pm

Re: Removing Lag from LOK

Postby OwnerOfSuccuby » Sat Mar 30, 2013 10:39 pm

No it really will not. I use this construction more then 7 years i think and it works good. Even better then some recomended ;)

If you do so - command start execute every fps times per second aqnd it is okay, may be if on the first frame you write gotoAndPlay 2 and on 2 frame gotoandplay 1 - then yes may be.

And then more moving objects - then more it lags - a lot of objects in LoK have not this construction that makes game lug. By the way if you make less quality of flash it becomes lug less - it can mean that the most problem is in graphic materials. It use to much CPU to move such many hard vector objects, when i test it in my vrsion i have the most problem becouse of this even after i remove gotoAndPlay() constructuins.
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm


Return to Tutorials



Who is online

Users browsing this forum: No registered users