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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:04:05+00:00 2026-06-03T15:04:05+00:00

I am working on a game that has destructible terrain (like in the game

  • 0

I am working on a game that has destructible terrain (like in the game Worms, or Scorched Earth) and uses pixel perfect collision detection via masks.

The level is a single surface and how it works now is that I create a copy every frame, draw all sprites that need drawing on it, then blit the visible area to the display surface.

Is there any way to avoid copying the whole level surface every frame and still be able to use the pixel perfect collision tools found in pygame?

I tried blitting the level surface first, then blitting every sprite on the screen (with their blit coordinates adjusted by the camera, except for the player character whose coordinates are static), but in that case the collision detection system falls apart and I can’t seem to be able to fix it.

UPDATE

I have managed to make it work the following way:
When drawing the sprites, I convert their game world coordinates (which are basically coordinates relative to the origin of the level bitmap) to screen coordinates (coordinates relative to the camera, which is the currently visible area of the level).

During the collision detection phase I use the coordinates and bounding boxes that are positioned relative to the level surface; so just like above. The thing is that the camera’s position is bound to the player’s position which is not and should not have been a static value (I am really not sure how I managed to not realize that for so long).

While this fixes my problem, the answer below is a much more comprehensive look on how to improve performance in a situation like this.
I am also open to suggestions to use other libraries that would make the ordeal easier, or faster. I have thought about pyglet and rabbyt, but it looks like the same problem exists there.

  • 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-03T15:04:06+00:00Added an answer on June 3, 2026 at 3:04 pm

    This is an issue that used to come up a lot in the days before graphics accelerators, when computers were slow. You basically want to minimize the work required to refresh the screen. You are on the right track, but I recommend the following:

    1. Keep a copy of the background available offscreen, as you are doing
      now.

    2. Allocate a working bitmap that is the same size as the screen.

    3. For each sprite, compute the bounding rectangle (bounding box) for
      its new and old positions.

    4. If the new and old bounding boxes overlap, combine them into one
      larger box. If they do not overlap, treat them separately.

    5. Group all the bounding boxes into sets that overlap. They might all
      end up in one set (when the sprites are close to each other), or
      each bounding box might be in a set by itself (when the sprites are
      far apart).

    6. Copy the background to regions of the working bitmap corresponding
      to each bounding box set.

    7. Copy the sprites for each set to the working bitmap in their new
      positions (in the correct z-order, of course!).

    8. Finally, copy the finished offscreen bitmap to the display surface,
      set bounding box by set bounding box.

    This approach minimizes the amount of copying that you have to do, both of background and sprite. If the sprites are small relative to the display area, the savings should be significant. The worst case is where the sprites are all arranged on a diagonal line, just barely overlapping each other. In this case, you might want to switch to a more generalized bounding shape than a box. Take a look at QuickDraw Regions for an example: Wikipedia Discussion Patent Source.

    Now, you may be thinking that the work to group the bounding boxes into sets is a O(n^2) operation, and you would be right. But it grows only with the square of the number of sprites. 16 sprites implies 256 comparisons. That’s probably less work than a single sprite blit.

    I focused on minimizing the pixel copying work. I must admin I am not familiar with the particulars of your collision detection library, but I get the idea. Hopefully that is compatible with the algorithm I have proposed.

    Good luck. If you finish the game and post it online, put a link to it in your question or a comment.

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

Sidebar

Related Questions

I'm working on a game that uses local area network. Like most of multiplayer
I'm working on a game that has simple pixel-art sprites. Since I'm planning to
Im currently working on a game that uses multi touch to apply zoom to
I'm working on a game that has many elements on stage, so I'm looking
I am working on a game that has AI logic, movement, etc and drawing.
I'm currently working on a basic javascript game that has two sprites that are
I am working on a game in OBJ C that has a ball view
I've been working on a little proof of concept game that has a rolling
I am working on a game that uses a grid system (think chess board).
I have a game I am working on that has homing missiles in it.

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.