CodeNewbie Community ๐ŸŒฑ

tankerguy1917
tankerguy1917

Posted on

pygame.transform.chop

Can someone explain how pygame.transform.chop works? The way I would think it works is you put in the coords and size of the section of image you want to chop, then you blit it to a surface, but when I tried to use it it did this
2000000
0111111
0111111
Imagine the picture is the numbers. I was trying to take out the 2 and blit it to a surface, but what the program did was cut out the 2 and the 0s and then blit the 1s. Is it just the fact that I am using an online IDE, or is that not how pygame chop works?

Top comments (3)

Collapse
 
eineki profile image
Eineki

As you already discovered, the chop works at the opposite of what you need. You select a cross to remove from an image and the remaining areas are glued together in a new image.

I drew to pictures to better explain what I mean:

  • you select the red area,
  • the red and yellow areas are removed
  • the remaining green parts are drawn toward the center and glued together. center removed

If you select a corner, you will observe exactly the behaviour you described (area color meanings are the same of the picture above):
sides removed

To select a rectangular surface of an image, mainly to get sprites from a spritesheet, you need to use the pygame.Surface.subsurface method. It define a child image of your main one ready to be blitted on a new surface or used as is.

Warning Changes to the main surface or to the subsurface will be reflected on the other one.

Collapse
 
tankerguy1917 profile image
tankerguy1917

thanks for the explanation!

Collapse
 
larrymartin1job profile image
Larry Martin

I have used pygame.transform.chop before and it usually takes in a Rect object for defining the section to be chopped. From your description it appears the blitting process might not align with your expectations.
Best Corporate Event Transportation Services in St. Augustine FL