import pygame
import sys
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([255,255,255])
# A transparent surface with per-pixel alpha.
circle = pygame.Surface((60, 60), pygame.SRCALPHA)
# Draw a circle onto the `circle` surface.
pygame.draw.circle(circle, [255,0,0], [30, 30], 30)
x = 50
y = 50
x_speed = 5
y_speed = 5
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
pygame.time.delay(20)
screen.fill((40, 40, 40))
x = x + x_speed
y = y + y_speed
if x > screen.get_width() - 60 or x < 0:
x_speed = -x_speed
if y > screen.get_height() - 60 or y < 0:
y_speed = -y_speed
# Now blit the surface.
screen.blit(circle, [x, y])
pygame.display.flip()
pygame.quit()
sys.exit()
我知道[30,30]部分是圆的原点位置坐标。
pygame.draw.circle(circle, [255,0,0], [30, 30], 30)
如果我更改[30,30]的值,则圆圈会被截断而不会改变 原始坐标。
=============================================== ======================
当我不改变形状并使球飞溅时,它会弹出而不会与窗户壁碰撞。
当我变形并溅起球时,它会与窗户碰撞并弹出。
让我知道如何保持圆圈的形状并使圆圈与窗口碰撞并弹出。