Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8881683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:23:38+00:00 2026-06-14T20:23:38+00:00

I have been trying to animate drawing elements without success. I can animate imported

  • 0

I have been trying to animate drawing elements without success. I can animate imported images, but when I try to animate drawings generated by pygame they remain static.

Edit: By “animate” I mean “to move”. As in making a circle move in x and y direction.

This is my code:

import pygame, sys
from pygame.locals import *

pygame.init()

FPS = 60
WIDTH = 600
HEIGHT = 500
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
ballx = WIDTH / 2
bally = HEIGHT / 2
ball_vel = [1, 1]
ball_pos =(ballx, bally)
RADIUS = 20

# Game Loop:
while True:
    # Check for quit event
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    # Erase the screen (I have tried with and without this step)
    DISPLAYSURF.fill(BLACK)

    # Update circle position
    ballx += ball_vel[0]
    bally += ball_vel[1]

    # Draw Circle (I have tried with and without locks/unlocks)
    DISPLAYSURF.lock()
    pygame.draw.circle(DISPLAYSURF, WHITE, ball_pos, RADIUS, 2)
    DISPLAYSURF.unlock()

    # Update the screen
    pygame.display.update()
    fpsClock.tick(FPS)

I’ve tried with and without locking/unlocking the display surface (as the documentation suggests). I’ve tried with and without erasing the screen before updating it (as some tutorials suggest). I just can’t get it to work.

What am I doing wrong? How do you animate drawing elements?

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:23:38+00:00Added an answer on June 14, 2026 at 8:23 pm

    You are not updating the ball_pos tuple: you set it to the start coordinates:

    ballx = WIDTH / 2
    bally = HEIGHT / 2
    ball_vel = [1, 1]
    ball_pos =(ballx, bally)
    

    You later update ballx and bally, but never set ball_pos again to ballx, and bally.
    In the while loop, after setting the ballx and bally, do this:

    ball_pos = (ballx,bally)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to create a ListView which I can sort using drag
I have been trying to animate a background position move from a div. The
Hi I have been trying to get this script http://jsbin.com/ipajo5/ working but using .live()
I am trying to animate a triangle when two triangles have been clicked twice.
I've been trying to smoothly animate some Windows Form location but I'm having some
I have been trying to solve this bug for 2 days straight and can't
I have been trying to figure this out but it seems no matter how
Have been trying to encrypt an xml file to a string so that I
Have have been trying to make a validator for my xml files. I have
I have been trying to setup git for our web development team unsuccessfully. Some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.