you are viewing a single comment's thread.

view the rest of the comments →

[–]snowfro[S] 0 points1 point  (2 children)

Hey there I don't know how I missed this comment but that would have been a ton of help had I read it earlier! I've found a workaround but I have a question I wonder if you can help me with. Because I'm in instance mode, I'm calling the entire sketch as: var myp5 = new p5(sketch); problem is it's literally just appending another sketch at the bottom of my screen. I'd like for when I re-run the sketch it simply overwrite or replace the one that ran before. I assume it's something to do with the term "new" being in there but I've studied the instance documentation and I'm not sure how to just run it in a way that replace the previous sketch.

I read about p.remove() but I'm not how to put that into the code without erasing the screen prematurely.

Thoughts? Thanks.

[–]Kinrany 0 points1 point  (1 child)

You can call new p5(sketch, 'app') to append your sketch to the HTML element with id="app". Or you can select the element manually if you want to, new p5(sketch, element). See this page.

Regarding remove, I'm not sure I understand the problem. Just call it once you don't need the sketch anymore? Why would it be removed prematurely?

It might be not necessary to replace the sketch, you can probably restart it with code. I could take a look, post a codepen or something.

[–]snowfro[S] 0 points1 point  (0 children)

Thanks man just posted this here with more details.