Reputation: 55
I am trying to make a circle that moves but I don't know how to make it work. I am using pygame as the package. I think it'll work if you update the circle but I don't know how to do that.
import os, sys, math, pygame, pygame.mixer
from pygame.locals import *
black = (0,0,0)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
white = (255,255,255)
run_me = True
screen_size = screen_width, screen_height = 600, 400
screen = pygame.display.set_mode(screen_size)
pygame.display.set_caption('ha ha ha ha ha')
clock = pygame.time.Clock()
fps_limit = 60
#circle
colorcircle = (red)
posx = 300
posy = 200
circle = pygame.draw.circle(screen, colorcircle, (posx, posy), 50)
while run_me:
clock.tick(fps_limit)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run_me = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
posx = posx - 10
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
posx = posx + 10
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
posy = posy + 10
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
posy = posy - 10
pygame.display.flip()
pygame.quit()
I want the to circle move somewhere depending on input.
However, the circle does nothing!
Upvotes: 4
Views: 15667
Reputation: 1
maybe adding a pygame.display.update() under pygame.display.flip() can work
Upvotes: -1
Reputation: 119
To move the circle, you have to redraw it every frame.
To do so, add the following to lines to your while loop (just before pygame.display.flip()
)
# fill the screen with black (otherwise, the circle will leave a trail)
screen.fill(black)
# redraw the circle
pygame.draw.circle(screen, colorcircle, (posx, posy), 50)
Upvotes: 5