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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:48:18+00:00 2026-06-05T07:48:18+00:00

Right now I have an x by y array to hold integers that decide

  • 0

Right now I have an x by y array to hold integers that decide which tile to draw to the screen. (The integers choose which tile in my tile_arr to blit)

For better performance, I only want the ints that changed to be blit’ed again.

EXAMPLE 1:

For example right now I have something like:

tile_arr = [image1,image2,image3,image4]
arr = [[2,2,2],[2,2,2],[2,2,2]]

Then depending on what the user does, some values in arr might change, so lets say:

arr[0][0]=1
arr[2][1]=1

Which would give us the array:

arr=[[1,2,2],[2,2,2],[2,1,2]]

now when blitting to the screen, I would blit images from the tile_arr: image numbers 1,2,2 to the top row, 2,2,2, to the middle row, and 2,1,2 to the bottom row. When I blit the array, I use a screen.blit for each value or arr, that’s nine blits. I would rather only do two blits. (Use screen.blit only twice)

EXAMPLE 2:

tile_arr = [green.bmp, red.bemp, blue.bmp]
feild_arr = [[0,0,0], [0,0,0], [0,0,0]]

Output:

G G G

G G G

G G G

User changes feild_arr to [[1,0,1], [0,2,0], [0,1,2]]

Output:

R G R

G B G

G R B

Now I only want to call sceen.blit() 5 times, leaving the 4 Green sqaures green, because nothing changed.

I thought of making another array, which would be just a copy of the first. Then run through it and compare to the new array to see what changed, but I think there is a better and faster way to this. Now the example is only 3×3 so making a duplicate array isn’t too bad, but I’m working with a lot bigger arrays, and when you’re blitting a 30×20 array, I need all the shortcuts I can get.

How do I only blit when the interger values in an array have been changed, and skip (don’t blit) the values that have not changed?

  • 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-05T07:48:21+00:00Added an answer on June 5, 2026 at 7:48 am

    You can use screen.blit only once, calling with a list of the rectangles that changed.

    I think the best aproach is to create you own class deriving from DirtySprite:

    class Cell: pygame.sprite.DirtySprite

    which already has attributes for holding an image and a rectangle and you can add an attributes to hold the number and a method to change de number that will set it as dirty.

    Then you can use LayeredDirty class to render the dirty sprites on the screen.

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

Sidebar

Related Questions

I have a multi-dimensional array right now that looks like this: function art_appreciation_feeds() {
so I have a mutable array that holds several circles which are UIViews. right
Right now I have def min(array,starting,ending) minimum = starting for i in starting+1 ..ending
I need help with this loop through an array. Right now I have 3
Right now, I have this code where $obj_arr maybe contain array and an object.
Right now I have an UIScrollView, which has a lot of UIImageViews, UILabels and
Right now I have these buttons that line up nicely, but they have some
Right now I have a tableview, and I can assure you that the delegate
Right now I have a function which takes my uploaded file, checks the extension,
Right now I have an array of std::strings, and have a function in my

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.