 # 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-redpos)**2+(greenpos-redpos)**2)-d

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

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 == blokje_3.pos && pacman_6.pos == blokje_3.pos) {
Score_ap = 10;
blokje.size = [0, 0];
}
if (pacman_6.pos == blokje_4.pos && pacman_6.pos == blokje_4.pos) {
Score_bp = 10;
blokje_2.size = [0, 0];
}
if (pacman_6.pos == blokje_3.pos && pacman_6.pos == blokje_3.pos || pacman_6.pos == blokje_4.pos && pacman_6.pos == blokje_4.pos ) {
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.