pygame

How to save an image after changing its resolution in Pygame?

How to save an image after changing its resolution in Pygame? Question: Currently, I am a beginner when it comes to Pygame, and have been trying to allow the user to hand-draw digits into a canvas. I have managed to get the code to draw and clear the canvas to work. However, the pictures I …

Total answers: 1

Keyboard Commands in PyGame

Keyboard Commands in PyGame Question: I have made a test code to try and solve this problem. I cannot figure it out. The test code takes in keyboard commands 1,2,3 into pygame and prints out whichever key was pressed into the console. I wrote the code with classes and stuff because it will later go …

Total answers: 1

Pygame resizable window when game is not active

Pygame resizable window when game is not active Question: How can I make the window in my game resizable only when the game is not active, when self.stats.game_active is False in my code. This is how i’m setting the window in the init of the main class: def __init__(self): """Initialize the game, and create game …

Total answers: 3

How to change style while rendering freetype.Font

How to change style while rendering freetype.Font Question: I want to be able to use bold or italic styles while rendering with pygame.freetype.Font, but it turns out freetype.Font.render doesen’t take any bold or italic keyword arguments. Instead it takes a style argument. I’m not sure how to use this though, please help me. import pygame …

Total answers: 1

How do I create an extendable bar sprite in PyGame?

How do I create an extendable bar sprite in PyGame? Question: I want to use the following asset in my game: It has specific pixelated borders and corners. So I want it to scale "extending" the inner part of the asset by repeating it until it matches the desired size. So I can render something …

Total answers: 2

Problem with Pygame Animating a Moving Sprite

Problem with Pygame Animating a Moving Sprite Question: I’m trying to make a game and when I want to make a moving sprite, there’s trail that is behind it. When I remove it, then the sprite is not animated. When I try to fix that, it stops moving. As far as I know the problem …

Total answers: 1

Unsupported image format error though images are all there

Unsupported image format error though images are all there Question: folder_dir = "Pieces" print(os.listdir(folder_dir)) for image in os.listdir(folder_dir): img.append(pygame.transform.scale(pygame.image.load(f"Pieces/{image}").convert_alpha(), (dimensions[0]/8, dimensions[1]/8))) I’m trying to load a list of images for my game but it keeps giving me this error: File "/Users/ragesh/Desktop/Coding_Work/ChessAI/main.py", line 31, in <module> img.append(pygame.transform.scale(pygame.image.load(f"Pieces/{image}").convert_alpha(), (dimensions[0]/8, dimensions[1]/8))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pygame.error: Unsupported image format I have …

Total answers: 1

Why is my colliderect() not working correctly?

Why is my colliderect() not working correctly? Question: Collision reacts to nothing, as if the platforms have shifted to the right. I am using it for the first time, so I would like an answer with an additional explanation… def collision(self, j): self.player_rect = pg.Rect(self.playerx, self.playery, player_w, player_h) for i in range(len(self.platfsx)): if self.player_rect.colliderect(pg.Rect(self.platfsx[i], self.platfsy[i], …

Total answers: 2