0

i try to create ellipse eye with pygame, and i have problem: my pupils overflow over eyes : my problem

and I search to get this result

my wish

my code is like this :

self.lastrect = self.display.fill((0,0,0),self.lastrect)
leftEye = pygame.draw.ellipse(self.display, (255, 255, 255), [int(self.startx -self.startx/2-self.eyeRadius),int(self.starty-self.eyeRadius*self.eyeRatio), self.eyeWidth,self.eyeHeight], 0)
rightEye = pygame.draw.ellipse(self.display, (255, 255, 255), [int(self.startx +self.startx/2-self.eyeRadius),int(self.starty-self.eyeRadius*self.eyeRatio), self.eyeWidth,self.eyeHeight], 0)
leftPupil = self.display.blit(self.pupil,(self.x-self.startx/2-self.rad,self.y-self.rad))
rightPupil = self.display.blit(self.pupil,(self.x+self.startx/2-self.rad,self.y-self.rad))

pygame.display.update([leftPupil,leftEye,rightPupil,rightEye,self.lastrect])

can you help me to find a solution to stop pupil's overflow outside Eye ?

flagadajones
  • 329
  • 3
  • 12

2 Answers2

0

While there's no doubt that masks would be the better way, I would do something different (and dumber). In short is that I would give the screen a white backround, blit the pupil, AND THEN blit the face (in your picture it is the black background without the eye slots. This may sound confusing so think about creating the same exact image but with a white background.

However, there are a lot of negatives to this if you apply it to a program with other shapes and images so you'll want to probably stick with masking anyways. But this could work

Ethanol
  • 370
  • 6
  • 18
0

I made it like this :

    mask = pygame.Surface(self.size, pygame.SRCALPHA)
    mask.fill((254, 195, 172))
    pygame.draw.ellipse(mask, (0, 0, 0), [
                        self.leftEllipseX, self.leftEllipseY, self.eyeWidth, self.eyeHeight], 0)
    pygame.draw.ellipse(mask, (0, 0, 0), [
                        self.rightEllipseX, self.rightEllipseY, self.eyeWidth, self.eyeHeight], 0)

    self.display.blit(mask, (0, 0), None, pygame.BLEND_RGB_MAX)
flagadajones
  • 329
  • 3
  • 12