Interactively controlling depth parameter of visual.Shape?

Dear all,
I am writing an experiment where, on a given trial, I draw a bunch of custom polygons (say 2) and then give the participants the control to change the position (via mouse click and drag), orientation (via mouse click + left and right arrow keys). I also want the participant to be able to change the the relative depth, say via up down arrow keys (i.e. in order to bring shape 2 in front of 1 or vice versa).

Position and orientation changes work fine. Also, the depth parameter of the polygon is clearly updated (I am reading it out for checking). However, the actual displayed depth is never changed, i.e. it does not reflect the numerical changes in depth made by the participant.

I have seen in the documentation that depth is deprecated. Is this why this parameter does not get updated when the participant changes its value via key press?

If it helps, here the bit of code that shows how, for example orientation and position changes work, but depth changes do not…

I greatly appreciate any help!
Best,
Katja
#######
if (piece.contains(mouse) and mouse.getPressed()[0] == 1 and ‘left’ in keys):

        piece.ori+=2.0
    elif (piece.contains(mouse) and mouse.getPressed()[0] == 1 and 'right' in keys):
        piece.ori-=2.0
        break
    if (piece.contains(mouse) and mouse.getPressed()[0] == 1 and 'up' in keys):
        piece.depth+=1.0
    elif (piece.contains(mouse) and mouse.getPressed()[0] == 1 and 'down' in keys):
        piece.depth-=1.0
    break 

I adjust depth using the order of drawing the stimuli. If I need to keep a static component visible in front of a moving one I change the opacity or the position by an imperceptible amount to keep it in front.

In your case I’m imagining a solution where there is a list of the depths coupled with the indices of each object, which can be sorted by depth after each depth change.

Thank you. Yes, that makes sense. I was just hoping for something more straightforward, because that strategy can quickly become complicated when I have 5 or more shapes to draw. But I’ll give it a try!

It should scale okay if you define your shapes in code and append them to a list, so you can refer to myShape[0], myShape[1], etc.