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 6541609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:07:30+00:00 2026-05-25T11:07:30+00:00

I’m playing with Pygame (teaching myself from the 2007 book Game Programming by Andy

  • 0

I’m playing with Pygame (teaching myself from the 2007 book “Game Programming” by Andy Harris.)

He gives several examples of moving sprites. I don’t see the difference between his examples and my code below, but my sprite (a fish jpeg that I made) doesn’t move. The “island” is also a jpeg that I made. Basically, the fish is supposed to move horizontally 5 pixels every frame. But instead, it just sits there. Maybe I’m just overlooking something obvious, or maybe there’s something wrong with my system (I have several versions of Python installed and the one that appears to be running the game says import error, no module named scrap).

[edit: I removed all my crazy OSX stuff b/c it’s pretty distracting and it wasn’t the problem].

import pygame  
pygame.init()  

screen = pygame.display.set_mode((800, 600))  
background = pygame.image.load('island_background.jpg')  
background = background.convert()  

class Fish(pygame.sprite.Sprite):  
    def __init__(self):  
        pygame.sprite.Sprite.__init__(self)  
        self.image = pygame.image.load('fish.jpg')  
        self.image = self.image.convert()  
        self.rect = self.image.get_rect()  
        self.rect.centerx = (600)  
        self.rect.centery = (500)  
        self.dx = 5  

    def update(self):  
        self.rect.centerx += self.dx  


def main():  
    keepgoing = True  
    clock = pygame.time.Clock()  
    fish = Fish()  
    allsprites = pygame.sprite.Group(fish)  

    while keepgoing:  
        clock.tick(30)  
        for event in pygame.event.get():  
            if event.type == pygame.QUIT:  
                keepgoing = False  

        screen.blit(background, (0, 0))  

        allsprites.clear(screen, background)
        #I thought the line above might be a problem, 
        #but commented it out and nothing changed (well, maybe I got a 
        #black background, but I don't recall. The fish just sat there in 
        #the same spot still

        allsprites.update  
        allsprites.draw(screen)  

        pygame.display.flip()  

if __name__ == '__main__':  
    main()      
  • 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-05-25T11:07:31+00:00Added an answer on May 25, 2026 at 11:07 am

    I’m Andy (author of the book you’re using)
    I answered your email directly, but if anybody else is reading, I’ll post here for the good of the SO community.

    It’s not a problem with OSX at all.
    All the Mac stuff is a red herring (sorry, it was a fish program… I couldn’t resist.)

    The problem is line 42:
    allsprites.update

    It should read
    allsprites.update()

    Here’s the subtle but crucial difference:
    In Python, a method or function also can be read as a variable. That’s a really powerful feature, but not one you’re using yet. If the parentheses are left off, it’s read as a variable (and it doesn’t do anything.) If the parentheses are included, the function is performed.

    You forgot the parentheses (in fact, some editors seem to remove them sometimes) and so Python happily accepted your code as legal instructions. However, it just acknowledged that there is in fact a method called allsprites.update. The update method was never called, so the sprite never updated, thus its position never changed.

    My version actually calls the update method of the sprite group, which in turn calls the update methods of all member sprites, and the program works just fine. Just to be sure, I have tested it on all three major operating systems (Ubuntu, Mac, and Win 7) and it is working fine.

    If you ever have doubts about whether code is working on your OS, please download my original tested code from my web site (http://www.aharrisbooks.net) and see if that’s working.

    Let me know if you get stuck anywhere else.

    BTW, I’m currently working on a game programming book for HTML5. Stop by my site for more info….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am reading a book about Javascript and jQuery and using one of the

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.