Optimisation Tips

See also:

for anything that you are using…

JS – is single threaded… (is this still the case in 2022?) – yes it is! https://www.geeksforgeeks.org/javascript/mutlithreading-in-javascript/

use anonymous functions (arrow functions) to reduce memory usage

Off load onto GPU

Graphics

Smaller images are usually painted faster than bigger ones.

Scaling is evil

Sprite sheets work a little slower than the individual images.

Decimal pixels kill performance

For rectangle collision system – use Separating Axis Theorem (SAT) developed by the legendary computer scientist Stefan Gottschalk. It capitalizes on the fact that, in any game, the chance that two objects are not colliding is far more likely than that they are colliding. It’s very efficient because you can find out immediately whether two objects might be colliding just by testing one axis. This means the collision function can skip most of the collision code most of the time. That’s great for games because it saves a lot of processing power. You can also use this same system for 3D collision detection. Just add an additional if statement to check for any overlaps on the third (Z) axis.

Use broad phase collisions – then narrow phase if and when needed

Resources