1 decade ago by lazer
I am having problems with system lag. I suspect that this has to do with garbage collection. Draw calls and entity updates are not slow at all and running well in the 60fps range, but the system lag causes my game to jitter and jump from 50-60 one second to 20-30 the next.
Question 1: I previously read that how variables are defined/used/reused plays a role on garbage collection, though how large of a role seems to vary depending on who you ask. What is the best way to define a variable in the main.js, for example. This:
Or should I just define "something" when I call the updateRows function, without bothering to set it to null beforehand? Does it make a difference? The same question applies to declaring timers, arrays, etc...
Question 2: Once I'm done with a variable such as the one above, should I set it back to null or delete it somehow, or just leave it as is and move on?
I wanted to just be clear about what the best practice is with these things, and what method works best with garbage collection/minimizing system lag.
Question 3: Is there a way to make my entity's draw only update at specific time and not each frame?
For example: I have instances of EntityBlock that are always stationary. The animation doesn't move at all. Every x seconds, the entities slide down 50px using vel.y and are then stationary again until the next x seconds have passed. I don't really need the game to redraw them each frame while they're just sitting there. Is there a way to only draw them when they're sliding down, and then "pause" the draw somehow until the next event?
Thanks for your help!
Question 1: I previously read that how variables are defined/used/reused plays a role on garbage collection, though how large of a role seems to vary depending on who you ask. What is the best way to define a variable in the main.js, for example. This:
something: null, updateRows: function() { this.something = blah; },
Or should I just define "something" when I call the updateRows function, without bothering to set it to null beforehand? Does it make a difference? The same question applies to declaring timers, arrays, etc...
Question 2: Once I'm done with a variable such as the one above, should I set it back to null or delete it somehow, or just leave it as is and move on?
I wanted to just be clear about what the best practice is with these things, and what method works best with garbage collection/minimizing system lag.
Question 3: Is there a way to make my entity's draw only update at specific time and not each frame?
For example: I have instances of EntityBlock that are always stationary. The animation doesn't move at all. Every x seconds, the entities slide down 50px using vel.y and are then stationary again until the next x seconds have passed. I don't really need the game to redraw them each frame while they're just sitting there. Is there a way to only draw them when they're sliding down, and then "pause" the draw somehow until the next event?
Thanks for your help!