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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:10:36+00:00 2026-06-10T03:10:36+00:00

I have a simple top down vertical shooter a la Galaga that I’m messing

  • 0

I have a simple top down vertical shooter a la Galaga that I’m messing around with. However, after looking through the documentation I’ve become a bit confused on how to efficiently load images, and whether to blit them every frame or not. All of the images are loaded through a few classes which inherit the pygame sprite class. At the moment, I’m loading the image as a class level attribute as such:

class Laser(pygame.sprite.Sprite):
    image = None

    def __init__(self, start_x, start_y):
        pygame.sprite.Sprite.__init__(self)

        self.pos_x = start_x
        self.pos_y = start_y

        if Laser.image is None:
            Laser.image = pygame.image.load('img/laser_single.png')
        self.image = Laser.image
        self.rect = self.image.get_rect()
        self.rect.topleft = [self.pos_x, self.pos_y]

I’m hoping this prevents Python from loading a new instance of the image into memory every time I create a new Laser(). But will this work as I anticipate?

The second issue stems from blitting all of the active sprites onto the pygame surface. At the moment I loop through a list of Laser(), Enemy(), and whatnot objects and blit each one individually before calling pygame.display.update(). It seems redundant to have to blit each object individually, so I’m asking whether or not this is the most efficient method pygame implements. Or, is there a way to blit every object at once and see some sort of performance improvement?

  • 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-10T03:10:37+00:00Added an answer on June 10, 2026 at 3:10 am
    • I’m hoping this prevents Python from loading a new instance of the image into memory every time I create a new Laser(). But will this work as I anticipate?

    Yes. Not only does this save memory, since every instance will just have a reference to the class variable, it will also increase performance because the image is only loaded once.

    • The second issue ssems from blitting all of the active sprites onto the pygame surface.

    This depends. If your framerate is OK, then stick with it. If your framerate starts dropping, have a look at DirtySprite, and maybe this article.

    Another python class that comes in handy is the LayeredDirty sprite group, which will automatically handle dirty sprites and updating only the relevant screen parts instead of the entire screen for you.

    • It seems redundant to have to blit each object individually

    With sprite groups, as e.g. the LayeredDirty or the simple Group, you add your sprites to the group once and just call the draw method of the sprite group.

    sprites = pygame.sprite.LayeredDirty((sprite1, sprite2, sprite3))
    sprites.add(sprite4)
    ...
    sprites.draw(pygame_screen)
    

    Using sprite groups will also enable you to do simple collision detection between groups using pygame.sprite.groupcollide and pygame.sprite.spritecollideany

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

Sidebar

Related Questions

I have simple element: <a id=a1 href=# style=position:absolute; top:0; left:0; nav-index:1; nav-down:#b1; nav-right:#a3; nav-left:#a1;
I am writing a simple top down RPG in Pygame, and I have found
I have a simple function that will scroll down to a div in dojo.
I'm currently working on a simple 2D top-down shooter in which you maneuver your
I'm creating my first game in Java. It is a simple 2D top-down shooter
I have a simple page layout with two divs--one on top, and one on
It's a very simple program. I have a function defined on the top and
I have simple php validation form that is halfway working. If you leave the
I have simple win service, that executes few tasks periodically. How should I pass
I have a simple Smart TV app that shows a list of items in

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.