Questions tagged [pygame]
A game development library based on the Python programming language. It wraps SDL for easy use alongside Python.
475
questions
0
votes
0
answers
19
views
Infinite scrolling with mouse
I know we're able to scroll a background image hardcoded or using awsd keys(or arrows) if they're pressed. But what about scrolling it with mouse movement? So I have a piece of panoramic image as a ...
0
votes
1
answer
59
views
Pygame code/file structure
I am currently working on a Pygame project and would like to seek your advice on best practices for organizing my code, particularly when it comes to creating additional scripts. I find myself ...
0
votes
1
answer
49
views
Sprite chasing a target using move_towards_ip does not move
I'm trying to get a turtle sprite to chase a falling algae sprite utilising Pygame's inbuilt functionality. I have spent many hours reviewing questions and answers and suspect I'm missing some ...
2
votes
1
answer
59
views
How do I mix an image with a specified color?
I have some images of static objects using per-pixel alpha (trees, rocks) for a background. In order to make them look a bit more natural, I want to create some kind of atmospheric fog, which means ...
0
votes
0
answers
18
views
Pygame showing surfaces at wrong coordinates with full screen
So I coded this line for the display surface:
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN|pygame.NOFRAME)
But the thing is, when I place a rectangle ...
1
vote
0
answers
52
views
Selecting Tiles Correctly With Scroll
I would like to understand the process of selecting the correct tile from a scaled Surface when I have information about the number of tiles on the x and y axes, the length of the Surface, and also ...
0
votes
1
answer
56
views
Sprite Animation in Pygame Zero
How do I use a sprite sheet in pygame zero?
The height of the images are 32, width is 25
0
votes
1
answer
46
views
Client and server with fixed tick in pygame
I'm trying to write a 2D RTS game with maximum of 10 players.
When server finish intializing each player receives start coordinates and game start time so each client will start processing ticks ...
0
votes
0
answers
44
views
pygame.error: video system not initialized
I don't know what's going on when I try to run pygame this error occures everytime no matter how much changes I have made.
HERE'S THE CODE:
...
0
votes
0
answers
31
views
Make pygame rectangle disappear when ball collides
So I'm doing a brick breaker game using Pygame. I want that everytime the ball hits a brick, that brick disappears (idk how)
Here's my code:
...
0
votes
0
answers
26
views
Why doesn't my image and text appear?
This is my code in question:
...
0
votes
0
answers
32
views
Perspective projection distortions
I'm building my own engine using python and pygame however my cube model is not able to be displayed correctly. This is my result after applying translation, scaling and projection matrices:
...
0
votes
1
answer
87
views
PyGame moves object in one direction but not in the opposite one
I'm having trouble with a PyGame animation I'm writting. I have a Ball class that defines an object that moves on the screen and bounces on the edges. I initialize ...
0
votes
1
answer
85
views
Perspective projection not working as intended
I copied a perspective projection matrix from here (https://jsantell.com/3d-projection/) and applied it to my vertices. It looks ok but without depth. Rotation matrices also work.
When I try to divide ...
0
votes
0
answers
36
views
PyOpenGL-Demo sample code -- exiting app doesn't work
I am using the cube.py sample from PyOpenGL-Demo, and there is this snippet there to handle the app exit when user presses the Esc key:
...
0
votes
0
answers
52
views
Why is my code giving an infinite while loop/crashing?
I have this large code that produces buttons that are meant to be clicked.
...
0
votes
1
answer
47
views
Why doesn't the fire appear when moving code to a function?
This is my code:
...
0
votes
2
answers
84
views
How do I get my character to move?
This is my code:
...
1
vote
0
answers
112
views
Why don't people use try-finally to call pygame.quit() in pygame programs?
I've seen several games made in Pygame, and none of them uses try/finally to call ...
0
votes
1
answer
201
views
Variable not updating while program is running
I am having issues where the variable action_cooldown does not update. I could remove this but then both the player and enemy attack at the same time, which is something you do not want in a turn ...
0
votes
1
answer
221
views
How to get better performance with pygame?
I'm not a gamedev, I'm a API/Cloud dev, performance has never been an issue for me since most of the time we are limited by network calls.
I've been playing with that for the past 2 days, I wanted to ...
0
votes
0
answers
91
views
How do I reduce the size of a sprite hitbox?
I am making my own pygame game, but I want to reduce the size of the player's hitbox in order to make dodging bullets easier.
...
0
votes
0
answers
86
views
Line collisions in pygame
I am very new to python and pygame.
I am taking a class and we have to do a simulation where lines are randomly generated, and we have to check if they intersect with 6 straight lines displayed on the ...
0
votes
1
answer
279
views
for event in pygame.event.get(): pygame.error: video system not initialized
I'm going through a tutorial and trying to build a game using Python and struggling to resolve below error. Not sure what I'm missing here can someone help with it
Alien_invasion.py
...
0
votes
2
answers
214
views
Collision detected early between images
Im making a "catcher" style game in python, where the player has to collect "Gems", and avoid the "Spikes". However the games collision detection is off by quite a lot. ...
0
votes
1
answer
407
views
Having trouble trying to figure out why pygame.sprite.Group's draw method isn't working properly, but switching to player sprite does work
Goal, Description & Scope (when encountered issue)
I was building a testing script to see how implementing different ideas (event handling, update handling, draw method) to loading sprite images, ...
0
votes
1
answer
170
views
Collisions detected prematurely, before rectangles actually touch
I am creating a game with Pygame but my collisions are registering too soon. I'm using this code to end the game when the player collides with a pipe:
...
0
votes
0
answers
19
views
Find which tiles are intersected between two points on an isometric tilemap [duplicate]
I need to be able to find out which tiles are intersected when a line is drawn between two points.
I'm currently working with a isometric perspective which makes things a little more complicated.
I've ...
0
votes
1
answer
89
views
How to move blocks down to fill the gap after clearing a row in Tetris?
I'm working on a Tetris clone. When I clear a line, my code does this:
I want to move the squares down + 1.
My code is:
...
0
votes
0
answers
57
views
Game window freezes whenever enter is pressed on textbox
I recently programmed a game in Pygame and added a text box (which I made using pygame_gui) which will send data directly to a MySQL database. But whenever I type ...
0
votes
2
answers
719
views
does having code spread in multiple files decrease performance?
Let's say there's a game that I could code in 1 file main.py but I decide to split it in more files like:
main.py
graphics.py
settings.py
interface.py
menu.py
and so on, would the game in turn perform ...
0
votes
0
answers
304
views
0
votes
0
answers
56
views
Emulating a Forza telemetry server and/or an OBD Bluetooth adapter (in Python)
I'm making a driving game in Pygame, and want to give a player the option to send game data to a Forza-compatible dashboard app (like SIM Dashboard) or to an OBD app (like RevHeadz). How do I do so?
...
0
votes
1
answer
2k
views
Creating a nav mesh
I'm coding a custom engine using Python and Pygame. It's a top down 2D isometric RTS and I wan't to implement pathfinding for my units.
My research has lead me to using a Navigation mesh which seems ...
0
votes
0
answers
59
views
Connecting nodes for A* algorithm
I am currently working on implementing a pathfinding module for my 2D game engine that I am writing in Python using Pygame.
Currently there are objects such as trees or buildings which can be placed ...
0
votes
1
answer
454
views
How fps limiting works in pygame (specific example)
I recently wrote a program where I needed to limit the fps. After some searching I found a way via pygame built-in methods pygame.time.Clock() and ...
0
votes
1
answer
149
views
Create list of images for animation
I'm using pygame and trying to create an animation by going through a list of variables:
self.image = self.walk_right[self.index]
I have loaded the images into ...
2
votes
1
answer
867
views
Pygame moving only once when key pressed integrated into player class
I'm having an issue when I have created a player class and want to move my sprite in between three lanes. I was able to get the sprite to move when I used ...
0
votes
0
answers
448
views
Pygame lags on simple game
I am trying to build a game in pygame, however any movement feels laggy. Its not a big lag but more like a small stuttering.
I created a boiled down version to showcase this.
The code in the git below ...
0
votes
1
answer
95
views
Pygame, jump counter resetting on first button press
Been learning my first platformer game based on this tutorial.
I decided I wanted to go off book and make it so the player could jump a second time before hitting the ground. I used the blit function ...
1
vote
1
answer
1k
views
Efficient way to check collisions for many objects
I am making a Bloons tower defense game and I came across a problem with regards to collisions. The way my code currently works is all the current bullets on the screen(could be potentially thousand) ...
0
votes
1
answer
336
views
How to convert a list into coordinates in pygame
I'd like to have a map in my pygame game but don't want to waste time moving each individual object in it. To resolve this, I'd like to iterate over a list like this:
[1, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, ...
0
votes
1
answer
418
views
How can I make a multi-line dialog box?
I'm trying to make a dialog box with pygame, and initially everything was going well. I printed the letters sequentially on the screen and it works very well in a single line of text, but when I use <...
-1
votes
2
answers
76
views
1
vote
1
answer
679
views
Using collision with classes in pygame
I am trying to make some games using classes. But I got a problem when trying to make the ping pong game. I made 2 paddles and a ball but I just do not understand how should I make the collision ...
0
votes
0
answers
16
views
Is there any way to compile a python script to web like unity webgl [duplicate]
I've been working on a game in pygame for a while and decided it was too much of a hassle to compile it to all the operating systems. So, naturally, I turned to the web. While I am well aware that you ...
0
votes
1
answer
3k
views
Why do I get this error: "error: video system not initialized"?
The error occurs when I call
keys_pressed = pygame.key.get_pressed()
Here is the full code:
...
0
votes
1
answer
210
views
In pygame I am trying to add the text as an integer and it keeps crashing, why?
I am trying to convert the string as an integer when I am using the font.render() function but it keeps saying different things like it has to be a unicode or ...
0
votes
0
answers
162
views
Need to see if you clicked a rectangle in a grid. (Pygame)
Basically, I created a grid with this:
...
0
votes
0
answers
165
views
Not being able to display pygame.freetype text
I'm trying to make a game where the player has to dodge asteroids coming, and I'd like to display the lives. I looked up some tutorials and decided to settle on pygame.freetype. When I run the code ...