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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:50:13+00:00 2026-06-10T06:50:13+00:00

I am trying to create a pacman game with pygame but I have run

  • 0

I am trying to create a pacman game with pygame but I have run into a few problems. It it saying that the ‘Food’ has no image.

This is my pacman game [code redacted].

The problem is this area here something is wrong and it tells me that food has no attribute image

class Food(pygame.sprite.Sprite):
    def __init__(self,x,y,color):
        pygame.sprite.Sprite.__init__(self)

        pygame.image = pygame.Surface([7,7])
        self.image.fill(color)

        self.rect = self.image.get_rect()
        self.rect.top = y
        self.rect.left = x
    def update (self,player):
        collidePlayer = pygame.sprite.spritecollide(self,player,False)
        if collidePlayer:
            food.remove
  • 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-10T06:50:14+00:00Added an answer on June 10, 2026 at 6:50 am

    Removing all the irrelevant bits, do you see the difference between the following Sprite subclasses’ __init__ methods?

    class Wall(pygame.sprite.Sprite): 
    
        def __init__(self,x,y,width,height, color):#For when the walls are set up later
            pygame.sprite.Sprite.__init__(self)
    
            self.image = pygame.Surface([width, height]) # <-------------
            self.image.fill(color)
    
    class player(pygame.sprite.Sprite):
    
        def __init__ (self,x,y):
    
            pygame.sprite.Sprite.__init__(self)
    
            self.image = pygame.Surface([13,13])  # <-------------
            self.image.fill(white) 
    
    class Food(pygame.sprite.Sprite)
        def __init__(self,x,y,color):
            pygame.sprite.Sprite.__init__(self)
    
            pygame.image = pygame.Surface([7,7])  # <----- this one is different!
            self.image.fill(color)
    

    The reason you’re getting an error saying that self doesn’t have an image attribute is because you didn’t set self.image, you stored the image in the pygame module itself.

    PS: The lines which look like

            food.remove
    

    seem suspicious to me. If remove is a method, it’d be called by food.remove(), and food.remove wouldn’t do anything.

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

Sidebar

Related Questions

I am trying to create a pacman-like game. I have an array that looks
I am trying to create a pacman game to learn XNA, but I am
So, im trying to create a pacman game in SFML, i created a class
Trying to create a notification mail to my clients that have invoices due. Here
I'm trying to create a basic Pacman game in C++ (I'll use Java syntax
I'm trying to create a Temp Table that has a key field that auto
Trying to create a black line in my view to separate text blocks but
Trying to create a new Dedicated Cache Role in Windows Azure but get the
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
I'm trying create a RCP Application with Eclipse, but I can't get past 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.