Most voted "pygame" questions
81 questions
Sort by count of
-
9
votes2
answers286
viewsIs it good practice to always manage mistakes with exceptions?
I’m creating a game with Python 3.4 and Pygame, and I’m using the paradigm object-oriented. In my classes, especially in __init__, am full the type checkings, to prevent Runtime errors. For example,…
-
4
votes1
answer735
viewsLosing image quality while resizing in pygame
I have some pictures of cards in size 140x190 and am using the method pygame.trnasform.scale to resize to 105x143 which is a proportional value. But it is losing quality, while the images of the…
-
4
votes3
answers275
viewsHow to configure pygame in English?
I’m playing a game with pygame. I want to show a text in Portuguese on the screen, but the same exchange "ç", "ã", "[", and "<" for "?" (question mark). import pygame class TelaInicial(): def…
-
3
votes1
answer112
viewsAttraction of objects in python
I’m writing a code where one image goes toward another only for some reason it’s not working. I take the distance between them calculate the gravitational force Fg = G*M1*M2/D^2 of attraction…
-
3
votes1
answer2229
viewsCoordinates of a Pygame image
How can I get the x and y coordinates of an image in Pygame? I need this for a game where I have to get the shot out right below an enemy. This is the code: # -*- coding: cp1252 -*- import sys…
-
3
votes1
answer1722
viewsIs it possible to create 3d games with pygame?
Is it possible? And if possible I need to know how to draw my own 3d images or is there a website that provides free 3d images?
-
3
votes1
answer524
viewsHow to insert animated gif into pygame
Good afternoon, I’m doing a college job, it’s a python game and I need to insert a gif in the code but when I use the command pygame.image.load("correr.gif") it shows the image of the gif frozen,…
-
3
votes1
answer65
viewsPygame how to make the character jump
I’m taking my first steps in pygame, and I’m trying to get the game character to jump, but I stumbled upon one mistake: the character just teleports up and down in 2 frames he did the whole move,…
-
2
votes2
answers205
viewsTypeerror: 'float' Object has no attribute 'getitem'
First, as soon as the mouse is clicked, the shooting angle ( that is the same angle of the player) is stored in the bullets_array list. Second, it is given speed to the shot through the 'cos' and…
-
2
votes1
answer7641
viewsPython - Libraries for MP3
I am conducting a project based on the Python language and that requires good performance in the playback of Audios (MP3). I am currently using the PyGame with his pygame.mixer.music to be able to…
-
2
votes2
answers1186
viewsHow do I resolve these libpng errors in pygame?
These errors are shown when I close the game: libpng Warning: iCCP: known incorrect sRGB profile libpng Warning: iCCP: cHRM Chunk does not match sRGB These mistakes happen because I’m using it:…
-
2
votes1
answer70
viewsHow to pass Keywords Arguments in python in a simpler way?
I’m trying to create the class button and trying to get the arguments I can pass pro rect, only if some argument is None and I pass for example self.rect = pygame.Rect(x=x) and the x for None of…
-
2
votes2
answers5610
viewsMP3 player with Python
I know almost nothing about programming and so I have been studying new possibilities, such as POO and the like. Recently gave me a desire to try to learn GUI and also to create an MP3 player, all…
-
2
votes1
answer960
viewsHow to run a function after a certain time in Pygame?
I’m making a game with Python, in which character jumps obstacles and falls after a few seconds. In javascript I used the setTimeOut function for this. In Python I tried to do the same thing with…
-
2
votes1
answer585
viewsError: "illegal target for variable Annotation" using "@Property"
Like pygame does not have a function similar to the library SFML -> View, I am developing a "camera" format to scroll the screen and preserve the positions of objects within the general…
-
2
votes1
answer1934
viewsPygame does not run a.mp3 file and returns pygame-error
I was touching the Pygame and when performing a program that plays music: from pygame import mixer mixer.init() mixer.music.load('ex021.mp3') # Dark Souls III Soundtrack OST - Main Theme.mp3…
-
1
votes1
answer728
viewsHelp with a simple game
Well, I’m trying to make a "ball" follow the rectangle of the game, but it doesn’t seem to be happening because the "ball" kind of blurs the screen when I move the player. I already looked for the…
-
1
votes1
answer348
viewsIs there a single way to use images in pygame?
I read in the documentation that the method exists image.load to read images, but it returns an object of the type Surface which is not always the most appropriate, so I wanted to know if there is a…
-
1
votes1
answer65
viewsIs it a problem to use pygame.image.load() multiple times?
I’m creating a class called Button, and one of the properties of this class is an image. I wanted to know if you have a problem, if within this class I used self.imagem = pygame.image.load() not…
-
1
votes6
answers2884
viewsmusic does not play
I have the following python code #*-coding:utf-8;-* import pygame pygame.init() pygame.mixer.music.load('ex1.mp3') pygame.mixer.music.play() pygame.event.wait() In this case, it should play a song…
-
1
votes3
answers648
viewsI can’t download "pygame" or "kivy" via the "Pip install..." command
When I try to download the pygame appears the following, remembering that my pc is windows 10 - 64bits. python 3.7.0b3 (64bits)
-
1
votes1
answer502
viewsHow to organize pygame code correctly?
I came from Javascript which is a little simpler than Python, there I didn’t need to worry too much about scope (almost everything was global) and not about code organization. But in Python even if…
-
1
votes2
answers2468
viewsDoubt about Keypress in Pygame
I have a question related to Pygame. I’m starting to move and I found a problem here. When I press the button A(left) I make the image walk to the left, until then everything ok. But if I hold down…
-
1
votes1
answer130
viewsHow to create a "trigger" function when a variable changes value?
Watching pygame.Surface.get_rect(), I realize that when I change a variable, for example left, pygame automatically recalculates all class variables (center, right, etc.). I’d like to know how it’s…
-
1
votes0
answers72
viewsHow to update the position of the text when changing the position of the button?
I have a boot class that is a Sprite and has as attribute text that is also a Sprite. I was wondering how to change the position of the text when I change the position of the boot rectum? import…
-
1
votes1
answer197
viewsWhy is such a simple game getting so heavy?
This is the first project I developed using Pygame. Because it’s a simple card game, I hoped it would be very light, but not really. As I am using a very weak computer (single core 1gb ram) it is…
-
1
votes3
answers484
viewsI can’t make the Pygame window close button work
I’m learning to use Pygame functions, but I got caught up in this problem. I created a window with Pygame, and then I made this code so when I click the exit button the window closes. Code while…
-
1
votes1
answer582
viewsHow do I pause a song in python?
I can make the program play the music, but the whole window is without function and only comes back to work when the music stops, that is to say creating a def button to pause the button only…
-
1
votes2
answers723
viewsAutocomplete doesn’t always work on Pycharm
I am starting the use of Pycharm, creating a test with Pygame. I realize that some Pygame methods do not appear in Pycharm Autocomplete. For example, if I want to put one pygame.mask.from_surface(),…
-
1
votes1
answer331
viewsHow to get a pixel color out of the screen limit in pygame?
I know to get a color of a pixel in Pygame I use get_at. But I have a huge background image and a lot of it is outside the screen area delimited by pygame. For example, a 1000x1000 image inside a…
-
1
votes0
answers33
viewsDo you have any python library for creating an online game? The idea is Tetris in pygame, in q in it you can fzr a X1 with someone on another pc
My idea is that the two X1 screens, appear to both players, that they can see each other’s moves in real time. I couldn’t find anyone who knows a library like this or who can teach you how to use…
-
1
votes0
answers47
viewsAbsurd performance difference between pygame.surfarray.array3d and array2d
Using the pygame.surfarray to control an image as an array, manipulating any element in an array3d is more than 5 times slower than manipulating an element array2d. See this benchmark: from datetime…
-
1
votes1
answer188
viewsComplex operations with Python (pygame.math.Vector2)
I am learning Python and I came across a complex expression that derives from pygame.Vector2: import pygame x = pygame.math.Vector2(1,2) b = x * 5 - (1, 2) print(x) print(b) Upshot: [1, 2] [4, 8] In…
-
1
votes1
answer748
viewsHow to make a program run inside a pygame window?
I made a window using pygame, and I have a code that I wanted to run inside it, but I don’t know how to do that, if anyone can help I’m very grateful. Here the window code: pygame.init() tela =…
-
1
votes2
answers91
viewsWhen changing the value of a variable, all objects in the same class are changing
I have a code that creates a class, with a location attribute, one (x, y). I ask the program to create 2 objects of this class with the random location attribute around a circle. However, they both…
-
1
votes0
answers57
viewsHow to capture the keyboard in the pygame during the game, where there is only sound?
So guys. I’m visually impaired and I’m starting now in game programming, trying to make a pygame game, but using only sound. But in the main menu I want to press the down arrow it goes to a "new…
-
1
votes0
answers38
viewsTrying to program puzzle changing elements into equivalent positions of two error arrays
I’m trying to make a puzzle in which the image comes scrambled into pieces, and by clicking on two different pieces they change position, if the drawing is correct it goes to the next. But the…
-
1
votes5
answers2318
views -
0
votes2
answers949
viewsHow can I use Pip in a python version installed by pyenv?
I installed version 3.6.0rc2 on pyenv and really need pygame in this version. I tried to use sudo pip uninstall pygame and sudo pip install pygame and also tried to sudo pip3 uninstall pygame and…
-
0
votes1
answer201
views"No module named pygame.base" - pygame and pypy
After several attempts and errors, I was able to install pygame 1.9.2a0 in pypy3, downloading the current version via Mercurial and installing via /path/pypy3 setup.py But when giving import, I get…
-
0
votes0
answers270
viewspygame.time.Clock.tick() why not use 60?
Why do most people use 40 instead of 60? 60 fps is no longer considered ideal? Is there a recommendation to use 40? And if I just call the method tick parameter-less?
-
0
votes1
answer93
viewsI am unable to use get_rect with Convert/convert_alpha and subsurface
I was doing so: class Esqueleto (pygame.sprite.Sprite): def __init__ (self): self.imagem = pygame.image.load("imagem/esqueleto.png") self.rect = self.imagem.get_rect() self.imagem =…
-
0
votes0
answers1024
viewsPygame - mixer.music()
I’m set up a system that uses Pygame tools, in other terms, I’m creating an application that runs songs, I’ve been trying to make that, with the current music ending (stored in one vector), the…
-
0
votes1
answer37
viewsWhat class should the text class inherit?
When using pygame it is very common for user classes to inherit from pygame classes, for example a class of characters usually vaqi extend the class pygame.sprite.Sprite. But a text class could…
-
0
votes1
answer1154
viewsGame Snake in pygame: Snake growth function
I’m writing Snake in pygame, but I don’t have a very clear idea how to implement snake growth functionality. I made a list ("lista_cobra") containing the coordinates of the head (which has…
-
0
votes2
answers107
viewsHow do you inherit a pygame class?
When I run this code (this is the current entire code, ie only 3 lines): import pygame class sp(pygame.sprite): pass I get: Typeerror: module() takes at Most 2 Arguments (3 Given) I would like to…
-
0
votes1
answer2103
viewsInstalling and importing the Pygame module in Vscode
I am learning to program python through Vscode and found it difficult to import the pygame module. import pygame pygame.init() pygame.mixer.music.load('nomedamusica.mp3') pygame.mixer.music.play()…
-
0
votes0
answers149
viewsHow do I make my music player choose an mp3 file and play it?
I’m having trouble making the program choose the music and play the selected music from tkinter import * from tkinter import messagebox from tkinter.filedialog import askopenfilename from pygame…
-
0
votes1
answer47
viewsHow to keep Sonic inside the screen? , n exiting from the sides
import pygame as pg pg.init() display_width = 1000 display_height = 600 color_black =(0,0,0) color_white = (255,255,255) color_red = (255,0,0) #tamanho da imagem sonic_width = 71 window =…
pygameasked 6 years, 7 months ago Patrick Gandolfi 1 -
0
votes0
answers19
viewsmy display does not open in pygame by vs code
i made an initial script of my game in pygame and the code is as follows: import pygame pygame.init() display = pygame.display.set_mode([840, 480]) running = True while running: for event in…