Is there a way to make a circle with my own picture with pygame?

Viewed 52

Hello i want to make a picture of type pygame.circle(something like get_rect() but circle). That's for an Billiard game and to be able to move them properly i think they would be circles. Here's the code:

import pygame
import pyautogui

width, height = pyautogui.size()

pygame.init()
screen = pygame.display.set_mode(pyautogui.size())
pygame.display.set_caption('Billiard')
background_image = pygame.image.load("Table.png")
background_image =  pygame.transform.scale(background_image, pyautogui.size())
ball_1 = pygame.image.load("Ball_1.png")
ball_1 = pygame.transform.scale(ball_1, (65, 65))
screen.blit(ball_1, [400, 400])
clock = pygame.time.Clock()
screen.blit(background_image, [0,0])

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    
    pygame.display.flip()
    clock.tick(30)

I want to make the balls as circles Thanks in advance

1 Answers

Create a transparent pygame.Surface object and use pygame.draw.circle to draw a circle on it:

radius = 20   # just for example
color = "red"

circle_surf = pygame.Surface((radius * 2, radius * 2), pygame.SRCALPHA)
pygame.draw.circle(circle_surf, color, (radius, radius), radius)
Related