We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there. In the p5 examples, I see images loaded in setup() and then drawn in draw(). However, when I draw four or so images in the draw() loop, the browser gets jerky/slow on browser window resize. I can fix this problem by calling noLoop() in setup, but that creates a whole host of other issues and workarounds (like trying to determine the value on change of a p5 slider).
I suppose my question is: are images really supposed to be drawn in draw()? Seems like drawing the image over and over again in this loop isn't the best use of resources - as evidenced by the slowdown on resize.
Maybe I'm missing a paradigm? I'm a newbie - so would be happy to hear how I'm supposed to be thinking about this. It just seems a little strange to put image(img, 0, 0) in the draw loop, when i know it's not going to change - unless there's a given user event. Know what I mean?
Answers
http://p5js.org/reference/#/p5/frameRate
http://p5js.org/reference/#/p5/noLoop
http://p5js.org/reference/#/p5/redraw
Are you using large images? What is their purpose in the context of your sketch? It may be that adding them by other means (e.g. CSS background) resolves the issues you're having...
Thanks for the tips. The purpose of the images is to create a swarm of creatures. So, I think I can't really put them outside of the draw loop. But think I'm clear on the concepts now. Actually, one thing that really helped to speed things up (on mobile in particular), was to set some viewport configs, as follows:
meta name="viewport" content="initial-scale=1"
(sorry, can't paste in the entire meta tag as it's being filtered out... even using markdown. anyhow, that's a standard meta tag)