Win10
PsychoPy version: 2020.1.3
Standard Standalone? (yes)
What are you trying to achieve?:
- I have a drag and drop experiment (code partly from Drag and Drop Builder Demo), in which two differently colored dots (image stimuli) can be picked and dragged multiple times over another (bigger) image stimuli
Problem:
The drawing order of the newly created pieces is wrong. The new ones always stay behind the bigger picture. But I want them to be on top of the bigger picture.
The depth of the new pieces always stays depth = (0.0)
; I would want them to be (-48.0)
instead, but it won`t let me change that.
What did you try to make it work?:
- without the creating new pieces part, the issue is not occuring
- the depth of the newly created pieces can’t be manipulated with
.setDepth
- tried to put the code for creating new pieces on the bottom of all the other image components, but that didn’t change anything
What I need help with:
effectively changing the drawing order for the via code generated newPieces or a code snippet that tells the new pieces to always stay in the foreground of the bigger picture
I’m adding my code and a picture to visualize what I try to do…
#Beginn Experiment:
#Drag and Drop Code from: [DragAndDrop PsychoPy Demo]
# creating pieces that can be dragged and dropped later on
def createPiece(piece, pos, name):
return visual.ImageStim(win, image=piece.image, name=name, size=piece.size, pos=pos, opacity=0.8)
def drawPicked(picked):
for each in picked:
each.draw()
def movePicked(picked, mouseMulti, grabbed):
#move piece if it is already being moved
if grabbed is not None and mouseMulti.isPressedIn(grabbed):
grabbed.pos = mouseMulti.getPos()
return grabbed
else: #move newly clicked piece
for piece in picked:
if mouseMulti.isPressedIn(piece) and grabbed is None:
return piece
------------------------------
#Beginn Routine:
polygons = [polygon1, polygon2, polygon3, polygon4, polygon5, polygon6, polygon7, polygon8, polygon9, polygon10, polygon11, polygon12, polygon13, polygon14, polygon15, polygon16, polygon17, polygon18, polygon19, polygon20, polygon21, polygon22, polygon23, polygon24, polygon25, polygon26, polygon27, polygon28, polygon29, polygon30, polygon31, polygon32, polygon33, polygon34, polygon35, polygon36, polygon37, polygon38, polygon39, polygon40, polygon41, polygon42]
for polygon in polygons:
polygon.setFillColor(None)
polygon.setLineColor(None)
pieces = [redPiece, greenPiece]
picked = []
newPiece = None
movingPiece = None
-------------------------------------------------------
#Each frame:
for piece in pieces:
if mouseMulti.isPressedIn(piece) and movingPiece is None:
newPiece = createPiece(piece, mouseMulti.getPos(), piece.image)
newPiece.setMask('circle')
picked.append(newPiece) #to drag multiple newly created pieces (but are hidden behind image/polygon components)
#picked.append(piece) #to create and drag only one piece (but correct drawing order)
#reset the newPiece to none, if one was just picked to be able to pick another one again:
if newPiece is not None and mouseMulti.getPressed()[0] == 0:
newPiece = None
movingPiece = movePicked(picked, mouseMulti, movingPiece)
drawPicked(picked)
Is there a way for me to get the new dots to show above the blue big picture??