Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

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:

        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!

1 decade ago by quidmonkey

1) Always define beforehand vs. adding dynamically.

2) Depends.

3) Draw a unit of stationary blocks to an off-screen canvas, then draw the canvas vs. individual blocks.

1 decade ago by lazer

Thanks, quidmonkey :) I actually found out in IRC that the massive system lag I was getting is specific to my Mac. Dominic tested on his PC and then I ran a few other tests as well and it actually seems to run at 60fps everywhere except this Mac at the moment. Nevertheless these things are still awesome to know, thanks!

1 decade ago by Jerczu

Beauty of the javascript is that you can define your object attributes/functions anywhere in the code, although its a good practice to define them at first although its your preferrence that matters if you will keep track of all attributes that you define anywhere in the code then dont bother defining them - youre the only one to code it right?
Page 1 of 1
« first « previous next › last »