Order of autodraw stimuli

Hi all,

I am designing an experiment in which a fixation dot is always being presented. Then, during the experiment, stimuli are flashed at a certain rate on and off. For both fixation dot as well as stimuli, I use the autoDraw option, because I am drawing everything on individual frame flips for the most accurate timing. I am experiencing that the stimuli are always drawn over the fixation dot, so that it appears that the fixation dot also follows an on/off process. Specifically, now, either fixation dot is drawn, or the stimulus. What I actually want, is the fixation dot is always drawn (over the stimulus).

Is there a way to change the order of autoDraw stimuli?

In pseudo code, to illustrate the routine, my experiment is as follows:

window = visual.Window()

fixdot = visual.GratingStim()
stimulus = visual.ImageStim()

fixdot.autoDraw = True
for i_frame in range(n_frames):
    if i_frame % (on_frames + off_frames) == 0:
          stimulus.autoDraw = True
    elif i_frame % (on_frames + off_frames) == on_frames:
         stimulus.autoDraw = False
    window.flip()
fixdot.autoDraw = False

window.close()

No, we don’t currently have a mechanism for autodraw order. You’ll just have to use draw() for your stimulus and autodraw for the fixation (autodraw is always done last)

1 Like

Thanks for your reply! Is there not anything that this order is dependent on? I tried for instance playing with how or in what order I add objects (visual.GratingStim or visual.ImageStim) to the window (visual.Window), but that seems not to matter. Is there any hacky way to manipulate the order? If not, I might have to go back to building the stimuli first, make a ‘screenshot’, and use ImageStim always.

I wouldn’t fixate on using autoDraw: it’s only there for convenience, but in your case, the code would be much shorter and more readable if you don’t use it at all.

window = visual.Window()

fixdot = visual.GratingStim()
stimulus = visual.ImageStim()

for i_frame in range(n_frames):
    if i_frame % (on_frames + off_frames) == 0:
        stimulus.draw() # conditional drawing
    fixdot.draw() # unconditional drawing
    window.flip() # show whatever was drawn

window.close()
1 Like

A tad late of a response but maybe for anyone else with a similar question -

the order in which autoDraw items will appear (or the layering of those items) seems to depend on the order in which their autoDraw attribute has been set to ‘True’.

so in the following code:

window = visual.Window()
objA = visual.ShapeStim()
objB = visual.ShapeStim()

objA.setAutoDraw(True)
objB.setAutoDraw(True)
window.flip()

objB will be displayed on top of objA. The to-be-autoDrawn items appear to be added to and drawn from an ordinal list.

If we wanted to switch this order, we would first need to set the autoDraw of objA to false (removing it from the autoDraw ’ list’), then set it back to true (adding it again to the end of the list) :

objA.setAutoDraw(False)
objA.setAutoDraw(True)
window.flip()

now, objA should appear on top of objB.

Note - in the last step, objA.autoDraw MUST first be set to False. If you simply try setting it to True again, it’s ‘position’ in the ‘list’ does not update.

1 Like