Replace the current text with new text

Hello,

How can I update the current text in the text(), now every time it will make a new text() element.
Code:

x = 0

def setup():
  size(500, 500)

def draw():
  global x
  text(str(x), 10, 10)
  x += 1
1 Like

Hi @cornedb2!

I’m not sure I understad you correctly, but I think you might be missing the frame “clean up”, try using background() like this:

x = 0

def setup():
  size(500, 500)

def draw():
    global x
    background(200)   # ops! GoToLoop saw I've misspelled it as blackground
    text(str(x), 10, 10)
    x += 1

Another idea is just to draw a small no-stroke rectangle, with the same color as the background, where the new text will be placed, so as to “clean” the pixels for it.

1 Like

Function text() also accepts a number as its 1st parameter: :nerd_face:

So there’s no need to convert it to a string: text(x, 10, 10) :wink:

A small mistype there: background(200) :face_with_hand_over_mouth:

2 Likes