psychopy.org | Reference | Downloads | Github

Overlaps() method on Pavlovia

URL of experiment: https://run.pavlovia.org/MRLab/temp_ef_math_tol

Description of the problem: I was using overlaps() to check whether to polygons overlap each other (e.g., red_circle.overlaps(blue_circle)) on Psychopy. However, this method doesn’t seem to work on Pavolvia. Is there an alternative for this method/function?

Thank you,

I’ve not heard of the overlaps method.

You could use an approximation by comparing the distance between the midpoints with the average of the sizes.

Thank you, I was afraid it was not going to be as straight forward as in Psychopy. I don’t have much experience with javascript. Do you have an idea on how the code would look like?

Thank you again!

Are you wanting to compare two circles? What variables are you using for their positions and sizes?

The code will be in Python but will auto translate to JS.

Yes, I am comparing two circles. Because of the way I am programming it, the distance, if they overlap, should always be zero. I guess I could do something like this (see below): storing the positions; then, comparing the variables; however, I was wondering, if there was something simpler.
greenpos = [(-0.35, 0.3)]
redpos = [(-0.35, 0.3)]
if greenpos == redpos:

Thank you

By overlap do you mean 100%? I assumed you meant overlapping at the edges.

The gap between two circles of diameter d is

sqrt((greenpos[0]-redpos[0])**2+(greenpos[1]-redpos[1])**2)-d

Thank you for your help. At the end, something like this did the trick:
ball_hand_box_3.pos[0]==greent1m2.pos[0] and ball_hand_box_3.pos[1]==greent1m2.pos[1]:

Ah. I use that in all my experiments designed for mobile phones to check the mouse position has changed before accepting a response. In JavaScript you have to compare individual elements of two list rather than the lists themselves.

Hi all, I am also using the .overlaps function and it works well offline using the builder interface (latest version), but not on Pavlovia. I created a pacman game where an image (two images: blokje_3, blokje_4) should disappear whenever the pacman moves over the image. There is also a sound that should be played at that overlapping moment and the mouth of the pacman should close.

The working code in psychopy is the following:

pacman_png= “pacman2.png”

if pacman_6.overlaps(blokje_3):
Score_ap =10
blokje_3.size=(0, 0)

if pacman_6.overlaps(blokje_4):
Score_bp =10
blokje_4.size=(0, 0)

if pacman_6.overlaps(blokje_3) or pacman_6.overlaps(blokje_4):
pacman_png= “pacman_closed2.png”
mySound_6.play()
else: mySound_6.stop()

Scorep = Score_Endp + (Score_ap + Score_bp)

if x>=0.8:
continueRoutine= False

I used the posts above to translate it into JS (not an expert at all), but this does not work.

pacman_png = “pacman2.png”;

if (pacman_6.pos[0] == blokje_3.pos[0] && pacman_6.pos[1] == blokje_3.pos[1]) {
Score_ap = 10;
blokje.size = [0, 0];
}
if (pacman_6.pos[0] == blokje_4.pos[0] && pacman_6.pos[1] == blokje_4.pos[1]) {
Score_bp = 10;
blokje_2.size = [0, 0];
}
if (pacman_6.pos[0] == blokje_3.pos[0] && pacman_6.pos[1] == blokje_3.pos[1] || pacman_6.pos[0] == blokje_4.pos[0] && pacman_6.pos[1] == blokje_4.pos[1] ) {
pacman_png = “pacman_closed2.png”;
mySound_6.play();
} else {
mySound_6.stop();
}
Scorep = (Score_Endp + (Score_ap + Score_bp));
if ((x >= 0.8)) {
continueRoutine = false;
}

My images are not circles so this could be the reason, but I did not find any other way to do it.

Thank you in advance for your help.