Change position of ImageStim in a trial

Hi All,

I’m trying to design an experiment, where in each trial I want to present two images and switch their location during the half way.

A part of my code now is:

if image_1.status == STARTED:
                # is it time to stop? (based on global clock, using actual start)
                if tThisFlipGlobal > image_1.tStartRefresh + 5-frameTolerance and  tThisFlipGlobal <= image_1.tStartRefresh + 2.5-frameTolerance:
                    # keep track of stop time/frame for later
                    image_1.tStop = t  # not accounting for scr refresh
                    image_1.frameNStop = frameN  # exact frame index
                    win.timeOnFlip(image_1, 'tStopRefresh')  # time at next scr refresh
                    image_1.setAutoDraw(False)
                if tThisFlipGlobal > image_1.tStartRefresh + 2.5-frameTolerance:
                    image_1.setPos(-0.5,0)
                    image_1.tStop = t  
                    image_1.frameNStop = frameN  
                    win.timeOnFlip(image_1, 'tStopRefresh') 
                    image_1.setAutoDraw(False) 

However, the code cannot function well in the expected way. I am wondering whether anyone knows how to improve it to implement the desired function. Thanks in advance!

What do you mean by:

What is your setup? You say you want to present two images. I assume, you’re working with the Builder interface and you’ve already set up two image components. Judging by your code, one of them should have the name image_1.

If you want to switch the position of your image after tChangePos seconds, you could use this code:

## In the Begin Routine tab
# put here the time after which you want the positions of the two images to switch
tChangePos  = 7.5 
posChanged = False
## In the Every Frame tab
# I'm assuming image_2 is the name of your second image
if (tThisFlipGlobal > tChangePos-frameTolerance) and not posChanged:
    image_1_oldpos = image_1.pos
    image_1.pos = image_2.pos
    image_2.pos = image_1_oldpos
    posChanged = True