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

  • Home
  • SEARCH
  • 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 8755145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:47:25+00:00 2026-06-13T13:47:25+00:00

I think the bug’s pretty self-explanatory, so I’ll just post the code and a

  • 0

I think the bug’s pretty self-explanatory, so I’ll just post the code and a screenie of what happens

'''
Created on Oct 29, 2012

@author: pipsqueaker
'''
import pygame, sys, random
from pygame.locals import *

frapsClock = pygame.time.Clock()

class Alien:
    def __init__(self, arg1, arg2):
        self.x = arg1
        self.y = arg2
    def move(self, craftx, crafty):
        if self.x < craftx:
            self.x += 1
        elif self.x > craftx:
            self.x -= 1
    if self.y < crafty:
        self.y += 1
    elif self.y > crafty:
        self.y -= 1

class PlayShip():
    def __init__(self, ag1, ag2):
        self.x = ag1
        self.y = ag2

class mainLopp():
    Board = pygame.display.set_mode((650, 500))
    pygame.display.set_caption("This")
    pygame.init()

    player = PlayShip(random.randrange(1, 650), random.randrange(1, 500))
    alienList = [Alien(random.randrange(1, 650), random.randrange(1, 500))]

    while True:
        pygame.draw.rect(Board, (0, 0, 255), (player.x, player.y, 12, 12))

        for currAlien in alienList:
            currAlien.move(player.x, player.y)
            pygame.draw.rect(Board, (255, 0, 0), (currAlien.x, currAlien.y, 16, 16))

        for event in pygame.event.get():
            if event.type == QUIT:
                print(alienList)
                pygame.quit()
                sys.exit()
        pygame.display.update()  
        frapsClock.tick(100)

the move() method is supposed to (over time) move the alien (red) to the player (blue). But when that code runs, this happensIt isnt supposed to be continuous like this

It isnt supposed to be continuous like that. Which begs the question, how do I fix it?

  • 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-13T13:47:26+00:00Added an answer on June 13, 2026 at 1:47 pm

    A quick fix:

    Precreate a color before your main loop:

    black = pygame.Color('black')
    

    and in your main loop:

    while True:
        Board.fill(black)
        pygame.draw.rect(Board, (0, 0, 255), (player.x, player.y, 12, 12))
    

    This will paint black over the entire screen, effectively erasing everything.
    This is OKAY because you re-draw everything again immediately after erasing it.

    In more advanced drawing code, instead of filling the screen (which can be slow), you would:

    • draw a black rectangle over top of the old sprite
    • then update the sprite’s position
    • then re-draw the sprite.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a simple code that shows what I think is a bug when
I think I might be causing a bug in my code because I'm unclear
I think I may have encountered a bug in mysql, or is it just
I think I've just found a really strange bug... But it can just be
I think I just encountered the strangest 'bug' I've ever encountered in my short
I think I found a bug in the libc++ list implementation. The following code
I think I've found a bug in Cake's FormHelper class, but maybe I'm just
Well, I think the ASP.NET MVC team released a pretty significant bug in the
I think I've just spotted an apparent bug in flex 4.5 . The link
I think there is a bug in codeigniter form validation class. My code is

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.