PixelArray.replace should be fine since it's just preprocessing and you aren't doing it every time around the game loop.
transform.threshold should be much faster for when that is necessary. There is some general information about thresholding using Pygame in the Camera module tutorial. http://www.pygame.org/docs/tut/camera/CameraIntro.html For this specific case, you'd want something like: pygame.transform.threshold(map_image,map_image,YELLOW, (0,0,0,0), BLUE, 1, None, True) Nirav On Wed, Mar 17, 2010 at 7:18 PM, Jordan - Necessary Games <[email protected]> wrote: > Hi Ian. I'm just trying to replace every instance of one color with another > color, before I render the map_image. Right now I'm using PixelArray to do > this, like so: > screen = pygame.display.set_mode(SCREEN_SIZE) > map_image = pygame.image.load('map_image.png').convert_alpha() > image_pixel_array = pygame.PixelArray(map_image) > image_pixel_array.replace(YELLOW, BLUE) > And then in my main game loop, I render with: > screen.blit(map_image, (0, 0)) > pygame.display.update() > > I've looked in the documentation, but I still don't get exactly how to use > transform.threshold... could you should me exactly how to use it, instead of > PixelArray, in the above example? Thanks! > > > > > On Thu, Mar 18, 2010 at 3:35 AM, Ian Mallett <[email protected]> wrote: >> >> On Mon, Mar 15, 2010 at 5:35 PM, Jordan - Necessary Games >> <[email protected]> wrote: >>> >>> Thanks very much for both replies! Pixelarray looks like it will do >>> exactly what I need at the moment. >> >> Actually, I think I may have to recommend the .transform function. PyGame >> changes . . . >> >> map_image = pygame.image.load('map_image.png').convert_alpha() >> #pygame.transform.threshold(DestSurface, Surface, color, threshold = >> (0,0,0,0), \ >> #diff_color = (0,0,0,0), change_return = 1, Surface = None, inverse = >> False): return num_threshold_pixels >> >> What specifically are you trying to do to to map_image? > >
