setAutoDraw for custom objects drawing in subsequent in routines

Hi,

I am creating some image components in code (instead of using builder’s gui icons). I do this to control draw order. Everything works fine but I am not able to turn that object from displaying in subsequent routines even when I do myobject.setAutoDraw(False) in the original routine. I couldn’t check out what is inside setAutoDraw though (it might be a binary?) , so I tried a flip(), to see if that would clear draw. But it didn’t. Any ideas?

thanks

By turn do you mean stop?

Please could you show a screenshot of your code component?

Yes, I meant “turn of” i.e. stop.

Here’s what the image looks like:

In the ‘Each Frame’ section, I have code that adds a fixation cross.

fixation = visual.TextStim(win=win, name=‘fixation’,
text=’+’,
font=‘Arial’,
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color=‘black’, colorSpace=‘rgb’, opacity=1,
languageStyle=‘LTR’,
depth=-3.0);

fixation.setAutoDraw(True);

The point of this is that the fixation cross is displayed over the image. This was important to get it working in the online version. However, that fixation continues to be drawn even in the next routine, which has its own images and needs no fixation cross.
I can’t get rid of the fixation cross. I tried turning off the auto draw in the ‘End Routine’ section like shown below.
fixation.setAutoDraw(False);
Even a win.flip() redraws the fixation cross in future routines. What is the way that I can turn it off?

thanks

You seem to be creating a new copy of the fixation cross every frame. I would put that code in Begin Routine and try not to set auto draw to true multiple times

You need it to be in the ‘Every Frame’ section because otherwise the fixation cross does not appear over the image in the online version. This is a bug reported in psychopy. And forcing a setAutoDraw helps enforce the draw in every frame.

Have you tried .draw() in every frame instead?

That doesn’t explain why you are recreating the object every frame.

Yes, I tried draw. It doesn’t work. The fixation cross does not appear over the image infront of the image when i use .draw().

Here’s an older thread that brings up the bug, similar to my situation. And the fix seems to be use setAutoDraw on the object that MUST be drawn above others. There are other similar threads.

https://discourse.psychopy.org/t/overlay-image-stimulus-on-top-of-polygon-stimulus/12707

Where is your code component in relation to your objects?

Components in a routine are played from top to bottom.

My solution in the thread you’ve linked was to have all of the overlapping objects defined in code but it might be okay to have the code component at the bottom.

How many times is

fixation = visual.TextStim(win=win, name=‘fixation’,
text=’+’,
font=‘Arial’,
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color=‘black’, colorSpace=‘rgb’, opacity=1,
languageStyle=‘LTR’,
depth=-3.0);

executed?

The answer should be one but you’ve said it’s once per frame.

I always keep the image component at the top, then the fixation cross, and then the code component at the bottom in case the code is custom.
However, the order of drawing (by moving components around in the builder) is done correctly when running offline via builder. It is NOT followed when running online , even though the same offline version of it works fine in the builder.

I have to draw it per frame because each of these routines - begin, perframe, end are individual functions and anything that you define in them are in local scope (scope of the function) and lost after. This is why moving the fixation code out of the frame will not work and doesn’t.

I’m sorry but I have to disagree with you here.
I’ve found that, for example
var x=1; has local scope but x=1; has global scope.

I’d recommend you have a read through of my crib sheet.

Hi!
You have an awesome crib sheet.
What you have suggest above, however, does not explain why the fixation cross is being drawn even when I have moved past the routine that does this. For example, if the next routine does not have anything to do with fixation cross, the fixation cross that was drawn with the setAutoDraw gets drawn in the middle of the screen.

It almost makes me think that setAutoDraw is stored in a list somewhere that keeps being drawn from , irrespective of the routine. Or something like that. Other than that, I cannot see a good reason for this happening.

What I think is happening is that AutoDraw is getting overloaded.

You shouldn’t have to AutoDraw on every frame – only on frames where something else changes.

I avoid having any components set to change every frame making all within frame changes in code.

Yes, ideally that is wise advise. However, the online version does not have a way to control draw order. Nor does it draw in order of appearance from top to down unlike builder which does. And hence, this workaround.

Is there a way to flush the draw calls after a routine?

This is going to be my last post on this thread.

You should be able to control draw order online (as I have done in my own experiments) if you create your objects in an earlier routine (which can be of short duration of start after the routine has been ended) and then set auto draw to true in Begin Routine in the desired order (and again on frames where the components are changed). Then set autodraw to False for all the code components in End Routine

Do you have a link to your design or do you know of a study that addresses this for online versions?

My design is significantly different since I also have controlled temporal display. But if you could point me to a link, I could do a comparative analysis to see if it might help me.

thanks again for your help