1

When I change the tab or I'm no focusing on the tab where canvas or my sketch exists, the drawing stops, I want it to continue drawing even if I'm not focusing on the page or tab where my canvas is. Like this example of code below, when I change to tab it stops drawing until I focus again on the tab. P.S: Just the canvas to continue drawing even if I'm not focusing on the page

var y = 0

function setup() {
  createCanvas(640, 480)
}

function draw() {
  background(255)
  fill(255, 0, 0)
  rect(0, y++, 64, 64)
  text(y,70,y+32)
  if (y > 480)
    y = 0
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.8.0/p5.js"></script>
Mostafa AGUERRAM
  • 573
  • 1
  • 7
  • 17
  • 1
    Possible duplicate of [Canvas doesn't repaint when tab inactive/ backgrounded for recording ( WebGL)](https://stackoverflow.com/questions/44156528/canvas-doesnt-repaint-when-tab-inactive-backgrounded-for-recording-webgl) – zero298 May 14 '19 at 13:51
  • 1
    This is the `requestAnimationFrame`. I have no idea if in p5.js you can choose to work with either `requestAnimationFrame` or `setInterval` UPDATE: According to [this video] (https://www.youtube.com/watch?v=CqDqHiamRHA) apparently `draw` is using `requestAnimationFrame` but you can bild a different function to use `setInterval` – enxaneta May 14 '19 at 19:26
  • @enxaneta thanks it's a good idea for a temporary solution, will changing my code to Webgl I guess, P5 it's not smooth. – Mostafa AGUERRAM May 15 '19 at 16:46

0 Answers0