Wakefield's Daily Tips

Use setAutoDraw() not draw()

Locally the logic is that if you draw an object in Each Frame code it will be drawn for that frame only, so it seems inviting to use .draw() for stimuli which you only want to be present for some frames in the routine. Unfortunately, this doesn’t work online, as this demo will show you.

text.draw() in Each Frame has the same effect in PsychoJS as text.setAutoDraw(True).

I therefore recommend that for objects designed to be shown for the entire routine, you use .setAutoDraw(True) in Begin Routine and .setAutoDraw(False) in End Routine.

If you want to control stimuli in Each Frame code, I would recommend checking the current value first, so change text.draw() to:

if not text.autoDraw():
     text.setAutoDraw(True)

and when you want to stop drawing use the opposite:

if text.autoDraw():
     text.setAutoDraw(False)

The code in my demo looks something like this:

if t < 1 or t > 2:
    if not text.autoDraw:
        text.setAutoDraw(True)
elif text.autoDraw:
     text.setAutoDraw(False)