Hi, I am new to psychopy and python, and am having drag issues with the click and drag function for my experiment. My experiment consists of a few still stimuli and a movable stimuli that is placed at a random position at the beginning of each trial. The goal of the experiment is for the user to align the movable stimuli with what they believe to be the center of the still stimuli. This repeats 4 more times (still stimuli move closer to the origin with each trial). I intended for the moving stimuli to be clicked and dragged with the left mouse button, and when the user thinks the stimuli are aligned, they move on to the next trial with a right mouse click. I have implemented this, however, I noticed that there is a significant lag with the mouse when the stimuli is dragged too fast. I consulted this forum post to fix this, and wrote my code as such:
# ------Begin Routine-------
continueRoutine = True
# update component parameters for each repeat
# setup some python lists for storing info about the mouse
gotValidClick = False # until a click is received
# keep track of which components have finished
if expInfo['Direction'] == 'Horizontal':
TrialPhaseComponents = [polygon, StillStimuli3, StillStimuli4, mouse]
for thisComponent in TrialPhaseComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
TrialPhaseClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
and:
# -------Frame Code-------
while continueRoutine:
# get current time
t = TrialPhaseClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=TrialPhaseClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
drag_in_process = False
if not drag_in_process: # check if one should be
if mouse.isPressedIn(polygon):
clicked_stimulus = polygon
drag_in_process = True
break
if True in mouse.getPressed():
if drag_in_process:
if mouse.isPressedIn(polygon, buttons=[0]): #left mouse button moves polygon
continueRoutine = True #left mouse does not advance trial
clicked_stimulus.pos = mouse.getPos()
elif mouse.isPressedIn(polygon, buttons=[2]): #right mouse button moves to next routine
continueRoutine = False #right mouse advances trial
else:
drag_in_process = False
As the title suggests, implementing this code now moves the experiment to a new trial with any click on the moving stimuli, instead of being able to drag and click the right mouse button, much less fix the drag lag. I tried multiple variations of the frame code but still no luck. Below I have attached a simplified, working version of my experiment before I tried to implement the lag “fix”. Any help would be greatly appreciated.
test.py (15.2 KB)