M
M
Mr_Edward2016-09-19 13:46:54
JavaScript
Mr_Edward, 2016-09-19 13:46:54

Nuances about setTimeout/setInterval performance in relation to canvas?

Good day, toasters. I decided to start learning javascript more deeply, not limited to one jquery or other frameworks. I decided to write a small game using canvas and immediately the question arose of setting the dynamics. Definitely one cannot do without setTimeout and setInterval (although the latter is in doubt). But I just imagined how many elements that move at the same time, so I thought about how quickly the browser could handle rendering at short intervals (50-150 milliseconds, or maybe more often). What do you recommend in terms of possible rendering optimization? Should I start with dynamic fractal construction?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rafael™, 2016-09-19
@Mr_Edward

use requestanimationframe

A
Alexander Korotaev, 2016-09-22
@lekzd

- Use 2-3 canvases superimposed on each other as layers;
- Cache in img everything that can be drawn in advance and use only drawImage() when drawing;
- Do not redraw everything that can not be redrawn.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question