18,028 questions
-1
votes
1
answer
30
views
Pygame Movement Stuttering
When I try to move Surface in Pygame, it seems to stutter in a weird way. Even when I use dt, the movement speed is not constant. Even thought FPS oscilate around 59-61, the Surface sometimes moves ...
-3
votes
1
answer
52
views
Exception 'FileNotFoundError: [WinError 2] The system cannot find the file specified' encountered while installing pygame [duplicate]
A few weeks back, I got a fresh new copy of Python 3.14 on my Windows 11 PC. So, as many of my projects use pygame and pgzero, I had to install it. But this bunch of error messages are appearing:
...
-2
votes
1
answer
68
views
Moving a figure around the screen using control keys [duplicate]
The figure moves in different directions: left, right, up, and down. While moving, it should also fire in the direction it's moving when the space bar is pressed. In this code, when moving to the ...
-2
votes
0
answers
53
views
Why is my Pygame background not updating properly?
import os
import sys
import math
import random
import pygame
from scripts.utils import load_image, load_images, Animation
from scripts.entities import PhysicsEntity, Player, Enemy
from scripts....
0
votes
1
answer
56
views
I need help getting the MOUSEWHEEL event to work [duplicate]
i'm trying to make it so that a surface moves whenever the user scrolls the mousewheel, like how this website moves when you scroll.
here's the code i'm working with so far.
scrollVal=74
for event in ...
-1
votes
0
answers
146
views
Y-axis rotation in python [duplicate]
So I was trying to make a 3d engine from scratch in Python when i tried to rotate the plane. All axes were fine as predefined rotations in 3d space, but when updating rotation in the code, only the x ...
-3
votes
1
answer
115
views
Pygame/Python window keeps crashing [duplicate]
I am a beginner to python & pygame, and im trying to make a pygame window. However, whenever the window opens, the window crashes and says not responding. can someone help me?
import pygame
...
3
votes
1
answer
104
views
Pygame window not appearing
I'm using replit as my IDE, and I installed everything correctly. for some reason, when I run the code, it says it's running but has no pygame window in the display tab.
my code:
import pygame
import ...
0
votes
0
answers
58
views
Pygame particles force fields swirly effects
I'm trying to replicate some animation concepts of particles with force fields in order to generate a vertical beam of particles going upwards, except they can experience "turbulences" at ...
-4
votes
1
answer
112
views
Pygame image not facing the mouse [duplicate]
Here is my rotating code:
pos = pygame.mouse.get_pos()
x_dist = pos[0] - self.rect.centerx
y_dist = -(pos[1] - self.rect.centery)
self.angle = math.degrees(math.atan2(y_dist, x_dist))
self.image = ...
3
votes
1
answer
158
views
Pygame sprite is not visible
I am making a game in which you have to roll the blue block to the "Touch me" text. When I run the code, the blue block is not visible and there are no problems found in VS Code. How can I ...
-2
votes
1
answer
122
views
How do I remove blurry rendering in Pygame or Pygame-CE?
I am trying to make a pixel-art 2d platformer in Pygame-CE. When I use a standard pygame display, the pixels come out as blurry:
Minimal Reproducible Example:
#Import everything
import pygame, sys
...
1
vote
1
answer
63
views
Creating a class instance causes pygame to draw a black screen for 1 frame
I have different screens/menus set as instances of the Scene class. Whenever I want to switch screens, my gameloop checks for a button click, and if successful, it calls a function that defines the ...
-4
votes
1
answer
98
views
Collision glitchy because of movement in pymunk
I'm working on a little project (a video game) that asks me to use accurate physics events. My goal is to have 2 rectangles who can move (here with the keyboard) and can collide. In case of a ...
1
vote
1
answer
367
views
DRI3, libEGL, and MESA errors in Pygame
When running my Pygame 3d maze, I encountered a new error when loading it up.
Here is my error:
Environment updated. Reloading shell...
pygame 2.6.1 (SDL 2.28.4, Python 3.11.10)
Hello from the ...
0
votes
1
answer
70
views
Strange behaviour of pygame.event.clear in a for loop
I created a way to handle the inputs for my pygame project, but made a mistake that resulted in a code that works the same way as the following:
def run(self):
got_mouse_click = False
...
1
vote
1
answer
149
views
How to implement drag and drop to basic pygame chess engine [duplicate]
I'm building a chess engine using pygame as a personal project. I was following a tutorial but I want to go further.
For the moment I have the chessboard, the pieces in their initial position and the ...
0
votes
1
answer
118
views
How to decrease the brightness of an image in PyGame?
I know there's a similar question here - How can I change the brightness of an image in pygame? - but the answer only explains how to increase the brightness, without referring to how to decrease the ...
-1
votes
1
answer
95
views
PyGame inputs not working with Nintendo Switch Pro Controller
I'm trying to add controller inputs to a game I'm making but when pressing one of the buttons on the controller, the action is not being performed.
I was told to use JOYHATMOTION but the Pro ...
-1
votes
1
answer
64
views
Pygame IndexError Rect displayed in middle correctly, trouble with mouse clicks [duplicate]
I'm trying to make a grid towards the middle of the window and can get the tiles to update however if I click where the tiles are visibly on screen I get an error.
The input seems to be stuck at the ...
1
vote
0
answers
130
views
Best way to do loops, slopes and tile handling for a Sonic game using Pygame? [duplicate]
I'm currently making a Sonic game using Pygame (full project here: https://github.com/Dingleberry-Epstein/Sonic-Pygame-Test) and I am stuck on how to perfectly handle loops, slopes and overall tile ...
-1
votes
1
answer
37
views
Pygame Timer Not Resetting on Restart [duplicate]
This is my first post, so I'm sorry if I do anything wrong. I'm developing a car game in Pygame (inspired by @javidx9 on YouTube), and I've run into an issue with the game timer. When the player ...
-2
votes
1
answer
50
views
How do I use the rect? [duplicate]
I am using
player = pygame.draw.rect(screen, player_color, player_pos, 30, 1, 1, 1, 1, 1)
with
screen as my surface
player_color as my color
player_pos as my rectvalue
30 as my width
1 as my ...
0
votes
0
answers
48
views
Sorting Isometric Coordinates [duplicate]
I am creating an isometric minecraft clone and am having no problems except for 1. Blocks need to be placed in order from right-to-left if going left and left-to-right if going right. Not placing ...
2
votes
1
answer
155
views
How to program angled movement (for a Sonic game)? [duplicate]
I've been trying to get a Sonic The Hedgehog game working in Pygame and it works for the most part. Sonic can run fast, jump across platforms like a normal platformer, gets affected by gravity, ...
-2
votes
1
answer
78
views
How do I use sine and cosine in pygame? [closed]
I imported math. whenever I try to use it and run the code, I get this error:
AttributeError: module 'pygame.math' has no attribute 'sin'
This is my code:
def move(steps,):
try_move(steps * math....
3
votes
1
answer
97
views
How to Use Windows System Menu via Python and Pygame
I have a fairly typical pygame project with a game loop that processes events, updates game state and data, and then draws the next frame. That's all working.
For various reasons, this is Windows only ...
0
votes
0
answers
70
views
How to make a ball decelerate in python/pygame? [duplicate]
I keep on finding people answer deceleration for characters but I can't find a way to apply this to a ball.
I tried just subtracting an amount from the balls x and y vel but one would go to zero ...
1
vote
1
answer
57
views
Object moves a little bit weird with pygame vector2
I have an issue with pygame module. I have a small program where user can click on any place in a window and a ball will spawn there and start moving up-left with 45 degrees angle (135 actually) and ...
-2
votes
1
answer
122
views
trying to execute openfilename(tkinter) with pygamewidgets button [duplicate]
im trying to make a tilemap maker and i stumbled on a problem when trying to get png file (tilesheet) the askopenfile function crashes, this is the button code
self.tilemap_file_button = Button(self....
0
votes
1
answer
111
views
Can I change the letter spacing of a freetype font in pygame?
I am trying to draw some text using pygame.freetype.Font however for this font to look good in the context it's in, I want it to have a custom letter-spacing/kerning. By this I mean the ability to ...
-1
votes
1
answer
84
views
Image in pygame is black
When I load my image in pygame (see code below), the image appears pitch black, instead of drawing properly!
Using Python 3.12.8
import pygame
pygame.init()
def imageload(imagepath):
return ...
0
votes
0
answers
33
views
404 error converting pygame to .wasm using pygbag [duplicate]
I'm trying to convert my pygame into .wasm using pygbag but getting the following error, as the site is no longer active:
ERROR 404: https://pygame-web.github.io/archives/0.9/pythonrc.py
Any ideas on ...
0
votes
1
answer
62
views
Why are images duplicated on a HyperPixel 2.0 Round Display Using Raw Framebuffer
I'm developing a Python application using the HyperPixel 2.0 Round display (480x480) on a Raspberry Pi Zero 2W running Debian Linux 11. When writing directly to the framebuffer, I'm experiencing an ...
2
votes
1
answer
97
views
Artifacts with pygame when trying to update visible sprites only
I'm learning the basics of the pygame library and already struggling. The "game" at this point only has a player and walls. There are 2 main surfaces: "world" (the actual game map) ...
0
votes
1
answer
79
views
Why pg.mixer.music.get_busy() returns False if music is playing [duplicate]
I was making an mp3 music player for myself. When pausing is enabled(key down), everything is fine, but if you turn off the pause, it skips the current music, although it should not do so.
I've ...
-1
votes
1
answer
43
views
Issue with Sprite not showing up, using Pygame [duplicate]
I'm following a begginner tutorial to start using pygame, but I'm stuck with the sprite display. I'm not able to make it visible on screen, please find below the code related to the sprite.
I'm not ...
0
votes
1
answer
101
views
Using python's bitwise & operator to check for flag in pygame surface doesnt return expected flag
While writing my game in pygame I was trying to use the XOR (^) binary operator to 'toggle' flags any flag I passed to a function. However I kept running into Overflow errors (and Warning: re-creating ...
0
votes
1
answer
73
views
Diagonal movement speed is faster, using an acceleration and friction movement system [duplicate]
I have made a top-down movement system in pygame, including acceleration and friction (the red square is the player):
import pygame
pygame.init()
running = True
x = 0
y = 0
speed = 3
friction = 10
...
-3
votes
1
answer
379
views
How do I install pygame on Ubuntu 24? [duplicate]
Pip doesn't work. Python3 base install on Ubuntu wants package installs via apt install python-xyz. And I can't find pygame
_@Sbox:~/Desktop$ python3 -m pip install pygame
error: externally-managed-...
0
votes
1
answer
83
views
How to prevent image blurring/flashing while moving?
I've recently created a camera which follows the player around the map. The camera centers the player in the middle and can zoom in and out with CTRL+Scroll wheel.
camera_handler.py:
import pygame
...
0
votes
1
answer
66
views
Difference between pygame and SDL draw rect
I am trying to figure out what's the difference between pygame and SDL2 rectangle drawing.
Here is my C code:
#include <SDL2/SDL.h>
const int WIDTH = 800;
const int HEIGHT = 600;
const int ...
-1
votes
1
answer
60
views
PyGame multipleobjects comparisons/collision detection [duplicate]
I was able to create the collision of 2 objects in PyGame using the calculation of Euclidian distance.
Circles created are moving on the screen, changing the coordinates based on the "gravity&...
3
votes
1
answer
89
views
Invert colors of a mask in pygame?
I have a pygame mask of a text surface that I would like to invert, in the sense that the black becomes white, and the white becomes black. The black is the transparent part of the text, and the white ...
-1
votes
1
answer
50
views
Tuple has no attribute 'colliderect'? [duplicate]
So I am making a game for a school assessment where a turtle has to get to the water. Previously, I was playtesting the game as the turtle being a rectangle. But now I want the turtle to actually be a ...
3
votes
2
answers
168
views
Text inside a pygame_gui textbox disappears after changing it - pygame_gui library
I am using the pygame_gui library. I am trying to make a textbox that when pressed enter it will print the text inside the box to the console and reset it (so the textbox will be empty).
It does ...
1
vote
1
answer
51
views
how to keep window color changed in pygame
Im trying to make it so when my picture bounces, the window changes to a random color, but when it changes, it only changes for a split second when it collides then the window changes back to white
...
0
votes
0
answers
41
views
Stack Overflow Error (0xC0000409) in Python Drawing App with Pressure Sensitive Stylus [duplicate]
I'm developing a drawing app in Python, and everything works smoothly with mouse input. However, when I use a pressure-sensitive stylus, the application crashes after a short period with the following ...
2
votes
0
answers
71
views
Pygame inherited classes acting differently [duplicate]
I'm making a python project for school, and created a general Enemy Class, which is then to be inherited by every common enemy. I created a Goblin Class that inherits this, and it works as expected, ...
-1
votes
1
answer
83
views
I’m having a problem in Pygame with displaying the sky [duplicate]
I'm making a platformer game, and I'm trying to create the world but the sky.png file doesn't show up. I tried with other PNG files, and it still doesn't work.
I inserted the location and coordinates, ...