How to scale every image in a list? pygame

Question:

How do I scale every picture within a list in pygame?

I can’t really figure it out. Whenever I try, an error says the item I am transform.scaling is a str or a bool and that I need a surface to work with. I understand that what I’m doing is wrong, but didn’t hurt to try and I didn’t know how to approach this. I am an amateur coder who just needs a little bit of help.

The relevant and most recent code:

rain_imgs = []
rain_list = ["1.png", "mv.png", "b1.png", "b3.png", "b4.png", "b5.png"]
for img in rain_list:
    rain_imgs.append(pg.image.load(path.join(img_folder, img)).convert())
    pg.transform.scale(img in rain_list, (60, 60))

The error:

TypeError: argument 1 must be pygame.Surface, not bool
Asked By: Yo Li

||

Answers:

I see that you’re trying to use

pg.transform.scale(img in rain_list, (60, 60))

to refer to the item you’ve just put into the list.
unfortunately, the ‘in’ keyword when used solo just tells you whether the item exists in the designated array, which is where the error is coming from.
What you might want to do would look something like:

for img in rain_list:
  img_item = pg.image.load(path.join(img_folder, img)).convert()
  pg.transform.scale(img_item, (60, 60))
  rain_imgs.append(img_item)

Which, instead of having to yank the item back out of the list to alter it, creats a local object, alter its features, then stores it, without the boolean error cropping up.

====Edit===

Since it’s now appending the original images, that tells me

pg.transform.scale(img_item, (60, 60))

Might be returning a new object, rather than running an alteration on the supplied one.
I would try something like:

for img in rain_list:
  img_item = pg.image.load(path.join(img_folder, img)).convert()
  rain_imgs.append(pg.transform.scale(img_item, (60, 60)))

see if that works.

Answered By: Bjorn

Here’s what I’ve been using:

scaled_rain_list = []

for img in rain_list:
scaled_rain_list.append(pygame.transform.scale(img,(60,60)))

This then makes the new list called ‘scaled_rain_list’ which stores all scaled up images.

Answered By: Faster Garlic