I do that a lot but don't know if it's a good idea or not, passing a lot of variables around to various functions, like, if (cando==true) {do lots of blocks of code} if (hasCertainItem==true){do half dozen if else statements}

So both inside and outside the canvas I have bars that adjust, monsters have one, the player has one, then outside the game canvas I have divs which update at the intervals above...

I consolidated several others I had into the ones above but don't see how to consolidate more....dunno what optimization to do there......

Question #4:

I have a function that sets key listeners, then when a key is detected it triggers a function to adjust the player.x, player.y by += or -= a positive or negative x, y, with a nested condition inside that function to translate the background.

It looks pretty crazy but it's really basic, the srcX and srcY are just positions of my sprite sheet to move when the key is down.

As you can see each key press has 3 more if statements nested, one triggers the sprite to shift every 6th game frame. Another checks to see if the sprite has shifted beyond it's last frame which resets it back to 0.

THEN the third nested if condition shifts the background in the direction the player is walking until it gets to the edge of the screen.

The problem is when I hit a bottleneck and the game freezes for a second, the player shifts in relation to the canvas and walking to the edge of the canvas, the player is out of sight OR the canvas has shifted and you can't get to the edge of it....is there a better way to tie the players position to the map so it doesn't shift unless the map shifts?

Anyone see any patterns from what I've posted with any thoughts on preventing bottle necks?

I just don't know if I should add more toggle counters so I only run things every 20-30 frames instead of every frame vs. using setIntervals...