| Reference | Downloads | Github

Outline Polygon When Clicked

Hi All,

I’m developing a program where subjects must click on a “button” (a white circle) on a VR schedule to elicit a reward. My subjects are not finding this very intuitive so I would like make the button more button like by having a small border appear around it while the mouse is clicked inside the polygon. I’ve tried a number of different pieces of code that attempt to change the polygon’s line color or size to no avail. What either ends up happening is no change in the borderline or the line appears but will not disappear after the mouse click has ended. Any thoughts would be appreciated.

In the example below, I have made the polygon have a thick white border around it at all times, and would just like the color to change to black when briefly clicked on.

if (mouseA_3.isPressedIn(TargetStimulusA_3)):
    TargetStimulusA_3.lineColor = [1, 1, 1]
    thisExp.addData('Time', t)
    thisExp.addData('Pos', mouseA_3.getPos())
    thisExp.addData('In_Stim', 1)
    while (mouseA_3.isPressedIn(TargetStimulusA_3)):

Hi @Benjamin_Seitz, you could set the polygon color to change whenever a valid click is reported. Using a code component, enter the following in the “Each Frame” tab - where polygon is the name of your stim.

if mouse.isPressedIn(polygon):
    polygon.lineColor = 'white'
    polygon.lineColor = 'black'

Hi David,

Thanks for the suggestion. I’ve been trying your suggested code which was similar to my first attempt and I think the problem lies on the builder side of things as I’m unsure of how to set the initial attributes for the polygon’s line color. Should the line color be set at constant, every routine, or every frame and what color should it be if I only want it to turn black when clicked on?

@Benjamin_Seitz, no problem, you should set the line color to constant, since you will be updating the code with the code component. Have a look at this example and let me know if you are still having problems
polyChange.psyexp (6.2 KB)

Thanks so much David this works great, I just needed to add your suggested line above my code that codes for data collection.

David’s Code works great but the outline around the polygon is only a quick flash, for those interested in a similar solution see my amended code. The time the polygon can remain highlighted is easily adjusted by changing the numerical value below.

start begin routine with. click_on = False and in every frame use:

if mouseA_3.isPressedIn(TargetStimulusA_3):
    if not click_on:
        click_on = True
        click_on = t # current time
        TargetStimulusA_3.lineColor = 'blue'
        click_on = t 
if click_on and t - click_on > .15:
    click_on = False
    TargetStimulusA_3.lineColor = 'white'
1 Like