risingBirdSong
risingBirdSong

Reputation: 348

P5 draw some items only once, but keep them rendered continuously

in P5 I have some drawings that remain static the entire time. It seems inefficient to put them in the draw method where they'll be drawn and redrawn again and again since they're not moving.

I tried placing the static drawings in setup but that doesn't work.

Is there a way to have some items drawn once and then kept statically rendered for more efficiency?

Upvotes: 3

Views: 1492

Answers (3)

Tony Zhang
Tony Zhang

Reputation: 427

you could just put it in the draw function if it's not too complicated. I can render thousands of ellipses moving around without lagging. if you are using a for loop to draw some very complicated pattern then you should probably use the createGraphics function. the reason that you can't put it in the setup function is that if you have a background in the draw function it basically clears everything on the screen every frame

Upvotes: 1

Adamsmashem
Adamsmashem

Reputation: 11

a simpler way is to put it in setup and make sure nothing is in draw

Upvotes: 0

Kevin Workman
Kevin Workman

Reputation: 42176

Sounds like you might be looking for the createGraphics function, which allows you to create a buffer that you can draw to. You'd only need to draw to the buffer once, and then you can draw the buffer to the screen each frame.

See this search for more info.

You can also learn more in the p5.js reference.

Upvotes: 3

Related Questions