0
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()

I know that the [30,30] part is the origin position coordinate of the circle.

pygame.draw.circle(circle, [255,0,0], [30, 30], 30)

If i change the value of [30,30], the circle is truncated without changing the original coordinates.

=====================================================================

when i do not deform the shape and splash the ball, it pops out without colliding with the window wall.

When I deform the shape and splash the ball, it collides with the window and pops out.

let me know how keep the shape of the circle and cause the circle to collide with the window and pop out.

SsolGom
  • 49
  • 1
  • 6
  • When you keep the origin as (30,30), the program works fine last I tested. The ball approaches, collides and bounces back perfectly with the wall. http://imgur.com/a/HtO6e . The reason your ball gets truncated when you change the origin is because you have blitted it on (60*60) surface. Only the part of circle which can appear on the surface is blitted while the rest which lies beyond the surface is cropped – GLaDOS Jun 11 '17 at 14:10
  • @GlaDOS Thank you for your analysis. Pygame.draw.circle () knows that it supports initial coordinates but I do not understand that I can not set the initial coordinates. – SsolGom Jun 11 '17 at 15:22

0 Answers0