0

I'm writing a CHIP-8 emulator with JavaScript, and I have determined that it is best to run the CPU in a Web Worker (I'm still not completely sure about that, but I've decided to go with it). I've read that all canvas drawing should be done inside of a requestAnimationFrame loop, but that pattern doesn't match that well to the Web Worker. How would I go about this? Would I have the main thread request the graphics state on every animation frame, or would I forgo using requestAnimationFrame and draw every time the graphics are updated?

robbie
  • 1,219
  • 1
  • 11
  • 25
  • I'm confused about the premise of the question. All animation must be done on the main (UI) thread, not in the Web Worker. You can use `requestAnimationFrame` or `setInterval` or `setTimeout`, but regardless, there needs to be some way to get data out of the Web Worker and onto the UI thread so it knows what to draw. – Jacob Krall Apr 23 '18 at 01:16
  • @JacobKrall My question is about how to transfer the data from the worker. Should the UI thread request the graphics state on every `requestAnimationFrame`, or should it draw every time the graphics are updated outside of `requestAnimationFrame`? – robbie Apr 23 '18 at 01:34

0 Answers0