[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Circle cut off at 60+fps, fixed by display.flip
Try this.
import pygame
from pygame import Color, KEYDOWN
w,h=800,200
fps=60
pygame.init()
screen = pygame.display.set_mode([w, h])
color=pygame.Color("white")
clock=pygame.time.Clock()
radius=20
x,y=800,100
speedx=-4
def get_bbox(x,y):
ÂÂÂ left = x - radius + speedx
ÂÂÂ top = y - radius
ÂÂÂ width = radius * 2 + abs(speedx) * 2
ÂÂÂ height = radius * 2
ÂÂÂ return pygame.Rect((left, top), (width, height))
while True:
ÂÂÂ old_x=x
ÂÂÂ x+=speedx
ÂÂÂ screen.fill(pygame.Color("black"),get_bbox(old_x,y))
ÂÂÂ pygame.draw.circle(screen, color, (x, y), radius, 1)
ÂÂÂ get_bbox(x,y)
ÂÂÂ pygame.display.update([get_bbox(old_x,y),get_bbox(x,y)])
ÂÂÂ clock.tick(fps)