Questions tagged [pygame]
Pygame is a set of Python modules designed for writing video games. Use this tag only if you are using the Pygame library and not if you have a question about programming a game in Python in general.
18,468
questions
-3
votes
0
answers
18
views
pygame stops and flickers without warning or any message [duplicate]
This is my first try to write something with pygame. I want a line on a circle rotating smoothly without any flickering.
This code flickers and stops without any obvious reason.
import pygame, sys
...
-2
votes
0
answers
21
views
Can't get the font to change, it always remains default
I have a config.ini file that works great. It draws from the folders in the directory no problem. The only problem is the font.
[Paths]
background_path = Backgrounds/BG1.png
background_path2 = ...
-1
votes
0
answers
23
views
How to restart simulation in pygame instead on pausing it> [duplicate]
What is happening in the code below is that when I click on the settings button the simulation pauses and takes me to a menu. When i click on the start button I want it to reset the simulation. What ...
-5
votes
0
answers
25
views
the screen.blit function in my code is not working and no image on my screen i coming please how can i enable this function? [closed]
I**
[```
your text*
want to get the background image ,the spaceship ad the aliens in my space shooter game using python game module and i am loading the images through python game image load but when ...
2
votes
1
answer
50
views
How do I palette swap sprites in pygame without the rectangle in the back
So I am making an auto generated game where in each level there is a different color palette. For now, I want to switch one color inside my player sprite. I used this video: https://www.youtube.com/...
-2
votes
0
answers
15
views
pygame objects collision, the player ghost of ladder issue [duplicate]
within the quoted code below i had attempted to make the player character detect all the sprites in a group using a for loop, the problem is basicaly when i press the s key and the player goes down, ...
-3
votes
0
answers
10
views
I getting error in my pygame program . It is a type error when I'm doing screen.blit [duplicate]
import pygame
pygame.init()
screen=pygame.display.set_mode((800,600))
pygame.display.set_caption("Space Invaders")
icon=pygame.image.load('ufo.png')
pygame.display.set_icon(icon)
...
-3
votes
0
answers
23
views
TypeError: rect argument is invalid - Python, pycharm [duplicate]
I tried this code:
import pygame
from pygame import Surface, SurfaceType
pygame.init()
white = (225,225,225,225)
black = (0,0,0)
gray = (128,128,128)
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 500
...
-1
votes
0
answers
12
views
Player image not being drawn onto the screen [duplicate]
I was writing some code that would draw a player flag onto the screen. It was working fine until the changed the screen saver from being a loop to a random image. After that the player flag is no ...
-1
votes
0
answers
33
views
Why does this slide puzzle only choosing the right-most column when randomizing the puzzle? [duplicate]
I'm trying to learn Pygame through this book my professor gave me years ago. I copied the program for a slide puzzle, but for some reason its not working. The game boots up, randomly moves only the ...
-1
votes
0
answers
20
views
Movement in pygame with inputs [duplicate]
I am trying to make Tetris, however, I cant figure out how to make the block start by moving one block, then speeding up again. Similar to how the actual tetris works (tetris.com/play-tetris).
I have ...
-1
votes
0
answers
68
views
Position of Bomb when firing
Can anyone suggest to me how to fix this? I went to find out what happening, then it was due to the rect.x of the bomb. However, when I fixed that it still struggled, my character when moving back or ...
-3
votes
0
answers
18
views
How do I make the player move in pygame program with OOP? [duplicate]
So, I am new to using the Pygame library. I am attempting to make a game with Classes in Object Oriented Programming, where the player can move with arrow keys pressed or WASD keys pressed, however, ...
-3
votes
0
answers
46
views
How to tell in Python whether a user's input is pure English letters or if an input method has been used? [duplicate]
I'm creating a small game using pygame, which involves a user input box. However, there's an issue when users input Chinese characters using an input method. In this case, my game captures the user's ...
-3
votes
1
answer
40
views
How to organise lots of variables in a program [closed]
I am coding a game in Pygame, which involves having loads of variables (loading images, creating rectangles, instantiating class objects) and was wondering if there was a better way of organising them ...
-1
votes
0
answers
18
views
need help fixing bugs in pygame [duplicate]
import pygame
from support import import_asset
class Player(pygame.sprite.Sprite):
def __init__(self, pos):
super().__init__()
# player graphics
self.import_player_assets(...
-2
votes
0
answers
27
views
pygame img not changing as intended [duplicate]
I am working in Pygame and I am trying to change the image of a character via its class instance.
This function is called every frame:
def work(self, t):
if self.cooldown < t:
...
-1
votes
0
answers
12
views
Is there a way to align my screen.blits to the center of coordinates without changing the coordinates? [duplicate]
I am making a game in pygame but I encountered an issue, If I screen.bilt something it, the coordinates that I give are the top-left of the blit
but then, I need to blit the image to the center and ...
-1
votes
0
answers
20
views
Location of pygame rects(bullets) not working as intened [duplicate]
I'm trying to create a small game where the player can bounce around the screen and shoot projectiles at enemies, however ii was having a problem with the bullets, so i started following this ...
-1
votes
0
answers
20
views
making player background invisible in pygame using png image [duplicate]
I am making a game using pygame. The player png that I have does not have a transparent background, so it has a blue square under it. Is there a way to remove this? And if so, how? I am just learning ...
-1
votes
0
answers
25
views
Image wont pop up on the screen [duplicate]
I'm messing around with pygame.transform.scale() but I cant see the player image that I have drawn over the surface I want to scale.
Here's my code:
`class Game:
def init(self):
#Display variables
...
0
votes
1
answer
23
views
Pygame Passing from main to game file causing errors
I receive a "pygame.error: display Surface quit" when trying to run the main.py file.
from Asteroid import Asteroid
import neat
import pygame
pygame.init()
neat.config.Config
Screenw, ...
-2
votes
0
answers
34
views
Pygame won't show line breaks [duplicate]
Whenever I make a text appear in my game instead of showing words than a line break then a word underneath the words, it shows words than a box character than a word after that. No line break at all.
...
-3
votes
0
answers
18
views
Issues regarding adding collisions and physics to jumping game [duplicate]
I added some collisions to the jumping game but having issues implementing it.
Here is the code attached.
I tried using normal physics and was expecting mario game like graphics and mechanism.
here is ...
2
votes
2
answers
72
views
How to place these images of ships?
I'm a beginner in Python. How can I place these objects in the dictionary self.x on the second half of window.
Here is some of my code:
win_w = int(input("Enter the number of pixels corresponding ...
2
votes
1
answer
30
views
Pymunk body object being problematic
I am using this video tutorial: Video
I am making a ball (with 0 mass at the moment) in pymunk and trying to show it on pygame but it is not working
I tried doing this to make a ball in pymunk and ...
0
votes
0
answers
33
views
Collision not working, causes UFO object to bounce [duplicate]
for context, this is for a college assignment, so I am attempting to change the base code as little as possible
This is pretty much a replica of a 'space invader' game and the assignment paper has ...
-2
votes
1
answer
23
views
speed changing for knives (obstacles) in pygame not working [duplicate]
I'm currently making a game in python (pygame).
I have a function called obstacle_movement which moves my obstacles
#change of speed for the knives as game progresses
changeofspeed = 0
def ...
1
vote
1
answer
22
views
Python PyOpenGl OBJ model shown with fliped normals
i made this small program using Python, Pygame, PyOpenGl and the objloader module (https://github.com/yarolig/OBJFileLoader), it just displays a OBJ model:
import pygame
from pygame.locals import *
...
-2
votes
0
answers
46
views
Black box appears in corner of object in pygame
My program was working as usual before I tried to increase the size of my rotating circle. This caused a black box to appear in the top left corner of the circle, which rotates together with the ...
-1
votes
0
answers
20
views
Why is my png not showing on my pygame window (replaced by a black window)? [duplicate]
I am very new to python and my teacher has, after a few math-related assignments, asked us to create a game using pygame. With the help of online tutorials and a bit of AI explaining (since my teacher ...
-1
votes
0
answers
19
views
Pygame Ticks isn't being multiplied in the while True loop [duplicate]
I'm working on a game in pygame, where a dinosaur jumps from wall to wall dodging knives. Theres a powerup cube called 'energy cube'. I'm making it so that every 10 score theres an if statement that ...
-2
votes
0
answers
25
views
Pygame - When game ends, and game starts the game immediately ends due to collision [duplicate]
I'm currently working on a pygame game where the dinosaur goes to the other side of the screen like in geometry dash. I'm not using classes, I'm a beginner at pygame and this is my first project.
The ...
-4
votes
0
answers
50
views
ImportError: cannot import name '_Group' from 'pygame.sprite' [closed]
from typing import Any
import pygame
from pygame.sprite import _Group
pygame.init()
width, height = 750, 750
window = pygame.display.set_mode((width, height))
fps = 60
clock = pygame.time.Clock()
...
0
votes
1
answer
57
views
Pygame while loop is interrupting in taking a value from a list
I'm currently working on a pygame game where the dinosaur goes to the other side of the screen like in geometry dash. I'm not using classes, I'm a beginner at pygame and this is my first project. I'm ...
-6
votes
0
answers
44
views
complicated bug in pygame physics program [closed]
I have been trying to solve this issue for some time now...
the idea of this project is that their is a planet in the middle and you can launch spacecrafts in different speeds and directions, the ...
-1
votes
0
answers
19
views
Getting segmentation error and my laptop restarts - Python Threads [duplicate]
I just started to write a simple Aimlab in python. I wanted to keep generating target while also acknowleding that I am clicking them. So I thought this is somewhere I can you multithreading and wrote ...
-1
votes
0
answers
17
views
When my object is rotates in pygame, it moves on the screen without me wanting it to [duplicate]
I am pretty new to pygame, but i am trying to make a game that includes rotating objects. When my circle rotates, it also moves in a bouncing way. I have tried to change the image to another circle, ...
1
vote
1
answer
28
views
pygame text gets out of the screen if increases to much
so something simple i am trying to make a simple idle game project in python pygame
and i encountered a problem while my "money" increases the text seem to get bigger from both sides and i ...
-2
votes
0
answers
37
views
How do I fix Pygame audio cutting out with too many sound effects?
When I use the "playsfx" function in my MusicPlayer class about 6 times the actual music stops. The music relies on a 2 channel system to alternate between bass and lead instruments during ...
-2
votes
2
answers
77
views
How to bounce object off wall based off edge of shape instead of center of shape? [duplicate]
At the bottom is my full code that bounces a ball around a screen, each bounce on a wall changes color and size of ball. It is bouncing a ball off the edges of the screen based on the center of the ...
1
vote
1
answer
51
views
pygame mask overlapping shapes of different color?
how is it possible to create masks of different color shapes on a surface and check for overlap collision?
suppose I have a green circle and a red polygon on a surface. I want to know when they end up ...
-1
votes
1
answer
40
views
How to stop .blit() from wrapping pixels across screen, or help finding an alternative that does the same?
I am trying to generate terrain randomly, and I have made it scroll it just as a test, but when the pixels hit the end of the screen, they play back on the other side as such:brokenscroll before ...
-1
votes
0
answers
31
views
Keep getting black screen for pygame output for particle model [duplicate]
I've been making a simple physics simulation and it's been going just fine so far.
After modelling the mass and velocity of the particles (via user input), I've also added a slider that goes up to ...
-1
votes
0
answers
18
views
Collisions not working with 'colliderect' [duplicate]
I'm currently working on a pygame game where the dinosaur goes to the other side of the screen like in geometry dash. I'm not using classes, I'm a beginner at pygame and this is my first project. I'm ...
-1
votes
0
answers
30
views
python pygame Two dimensional platformer that the collisions do not work as they fall through platform or do not stop [duplicate]
i am making a 2d platformer and the gravity will pull the player through the platform and the collisions do not stop the player even when it detects it collides
i used collide rect to detect when the ...
-3
votes
0
answers
37
views
Why do my particles always form triangle structures in pygame? [duplicate]
I am making a sandbox in pygame and the sand always forms strange structures, the structures are like this:
Why do the particles always form like triangles? Here is the base class:
class Particle:
...
-2
votes
0
answers
28
views
Why does KEYDOWN not work, while KEYUP works just fine? [duplicate]
I have tested using the print method, and so far KEYUP prints just fine, however KEYDOWN, nothing happens. I am failry new to programming, any help would be nice. Here is my entire script:
import ...
0
votes
0
answers
31
views
How to make an object move continuously diagonally in pygame? [duplicate]
I'm very new to pygame as well as python and making a 2D shooter where you can shoot a bullet when the mouse is pressed. The bullet should be drawn initially at the player and move diagonally ...
-1
votes
0
answers
25
views
Cannot exit fullscreen but can enter it [duplicate]
The default is non-fullscreen, and when I press f11 to enter fullscreen it works fine. When i press f11 again to exit fullscreen, it glitches and temporarily exits fullscreen but enters it straight ...