Questions tagged [pygame]

0

votes
1

answer
20

Views

How to intoduce randomness in pygame?

I'm trying to create a starry night in pygame. It was actually given as exercise in the book I'm following Python Crash Course by Eric. I have so far created a co-ordinated fleet of stars but according to the task, I need to place stars randomly using randint. I can't conceive how to make it? I'm a...
the_paste_rover
0

votes
0

answer
12

Views

Python pygame how to shoot bullets from player

I'm trying to get my code to shoot a pygame.rect across the screen from player location. Right now it shoots but when I let off the space button it doesn't reset the rect. I have it set to change the x coordinate but I want it to reset after I release the space button. if event.key == pygame.K_SPAC...
BrandOcOder
1

votes
2

answer
25

Views

I keep receiving an attribute error in Pygame when attempting to create a window

I have only today started using pygame, and am just getting familiar with how to use it. I want to start out by simply creating a blank window. I have attempted using the code below: import pygame pygame.init() screen = pygame.display.set_mode((400, 300)) done = False while not done: for event in py...
Wispaman8
0

votes
0

answer
15

Views

How do I make my Sprite appear in my window?

I have made an enemy sprite within my game, however it is not displayed on the screen. I am wondering how I would be able to make it appear? Tried updating the pygame display in the class but it still won't show the image. I plan on making the sprite appear in order to allow it to move to the end of...
Zak Chaudhary
1

votes
2

answer
78

Views

Hard to find bug that involves strange physics behaviour in pygame code

First I'll say I'm pretty tired I've been up about 22 hours straight. Anyway I have this funky physics problem in a PONG game. You know the old classic. I have been looking at the code for a LONG time trying different variation, commenting out certain parts etc. and I can't find the damn bug! Can s...
Chakotay
1

votes
2

answer
827

Views

Pygame: Set alpha level for shapes

How would I go about setting the alpha value of a pygame shape: pygame.draw.circle() I tried using an RGBA value, but to no avail.. here is the draw code: pygame.draw.circle(screen, ((0,255,0,alpha)), (px,py), 15) px and py are the player's (circle's) position. alpha is just a place holder for what...
Sam Tubb
2

votes
0

answer
11

Views

How can I retrieve coordinates of a pymunk.Circle?

I'm new to python so please forgive me if I'm misnaming pygame objects. I've been tasked to build a virtual Pachinko gaming machine. I'm having trouble getting the coordinates of the ball as it falls through the window. I need the coordinates to keep track of score and reset the loops so the user ca...
Tarps
0

votes
0

answer
12

Views

Why is pygame trying to play a sound that doesn't exist?

I'm developing a game and using the pygame module to run sound. At one point, I included two files, Monster.ogg and woodfrog.ogg, as sound files for various classes. Those files are both absent now, unreferenced in the code and deleted in absolute terms. For some reason, pygame.mixer.Sound keeps ref...
Jake
1

votes
1

answer
62

Views

Colliding rectangles without classes in python

So I'm making this cool avoiding game and I've got everything done except for the collision. Since I'm a noob to the pygame module, I didn't do any classes, and I don't know how I would check if the player hitbox collides with the enemy hitbox. Also, I know a few people have asked this before, but t...
Sheepy
1

votes
2

answer
56

Views

scoreboard in pygame not putting players in order or even not showing them

I have spent about 2 weeks creating a game on pygame and I am nearly finished the only part that I am trying to add now is a score board for first place and last place (The reason I did this was because I was not too sure how to create the middle rankings or places). I have created a way to check o...
Ugandan_Knuckles
1

votes
1

answer
424

Views

Pyttsx “run” but without “wait”

I'm using pyttsx in my game, but I have encountered a problem - method runAndWait() causes it to stop for a brief period of time to say the queued text. It is a problem, because it messes up my time counting. Is it possible to say a text but without stopping all other activities? Or maybe is there a...
Bazyli Polednia
1

votes
1

answer
60

Views

Polyphony with Pygame channels

I am trying to trigger audio samples in Python on a Raspberry Pi 3, with physical buttons. The idea is that when I press a button a sound plays. I have been using the Pygame library's channels to achieve (or at least mimic) polyphony. The code that I have been trying to implement is as follows: (sou...
calslate
1

votes
2

answer
499

Views

Pygame mouse hold

I am designing an incremental/clicker game in pygame, and I want to change the $ counter by 1 every click. However, I can hold the button down, and I can't find a way to limit this. My button class is below: class Button(object): def __init__(self,x,y,width,height,color): self.rect=(x,y,width,heigh...
gnawydna
1

votes
0

answer
314

Views

Pygame Display.Update() Fix?

When programming in Python 3, using Pygame, there is a problem with updating portions of the screen on Mac OS. For example: import pygame screen=pygame.display.set_mode((200,200)) screen.fill((100,100,100)) pygame.display.update(0,0,100,200) This should display a screen half grey and half white, how...
PatrickHume31
1

votes
1

answer
58

Views

pygame e.button not working

I'm trying to capture the position of the mouse when it is first clicked. I am getting this error: AttributeError:'Event' object has no attribute 'button' Question: What does this mean and how do I fix it? My code: running=True while running: for e in event.get(): print(e) if e.type==QUIT: running=F...
Kirara
1

votes
2

answer
64

Views

Moving Sprite issues

When this part of the code has been run, it shows the sprite however when the arrow keys are pressed nothing moves, ive tried to use print statements to attempt to debug but nothing has come up, what is the issue and how do i solve it? Here ive added everything relating to the movement in my program...
1

votes
1

answer
48

Views

converted pygame closes immediately

I converted a pygame file to exe with cx_Freeze, and the process went fine. However, when I click on the executable, it opens, then closes immediately. I'm wondering if it's a problem with either main file or my setup.py? Main: import pygame pygame.init() white = 255,255,255 #This block defines all...
Zayed Azam
1

votes
0

answer
424

Views

Import of pygame fails - from pygame.base import * ImportError: DLL load failed: The specified module could not be found

I've seen a bunch of similar questions posted here but no solution. I have recently installed Python 3.6.4 and put Pygame into my c:\Program Files (x86)\Python36-32\Lib folder. I can import other Python modules such as math OK but 'import pygame' gives me from pygame.base import * ImportError: DLL...
johnmycroft
1

votes
2

answer
42

Views

Fullscreen toggle seems to instantly go back again

I'm new to python and i was trying to let the 1-button on the keyboard toggle fullscreen in an application using pygame. Somehow the else: statement causes it to instantly go back to windowed mode again. At least that is my understanding. Can anyone enlighten me why that happens and care to give an...
J Kroes
1

votes
0

answer
91

Views

While loading image sequence in an array, pygame.error: Out of memory

I have an animated background, and because loading the image every frame takes way to long I created an array in which I load all the images on startup. self.spriteArrayBG = [] i = 1 while i
John Cadac
1

votes
1

answer
24

Views

How to always have text centred in the x-axis in Pygame

I have a text display function below: def display_text(text, color, x, y, font): text_image = font.render(text, False, color) text_rect = text_image.get_rect(x=x, y=y) gameDisplay.blit(text_image, text_rect) How would I edit this so the text displayed on the screen is always displayed in the centre...
helpmecode
1

votes
0

answer
359

Views

python pygame.error: video system not initialized

I am trying to open a window in pygame but keep getting this error: Traceback (most recent call last): File 'python', line 3, in pygame.error: video system not initialized This is my code: import pygame pygame.init() pygame.display.list_modes() pygame.display.set_mode([700, 500]) black = (0, 0, 0)...
Ben Harper
1

votes
1

answer
208

Views

Pygame Window created in the background

When I start my program that has to open pygame window, it opens it behind the current window. What have I to write to make a focus on pygame window and it won't be as background? This is for a game for mathematics revision so I need to use the python shell as well, in this example for (1+1). This...
user9156598
1

votes
1

answer
542

Views

How to play the next song in file after the song is finished automatically using pygame

I'm making a music player using pygame. But I cannot understand how to play the next song automatically after the previous song is finished. My program is reading all mp3 files in a selected folder first. Can you tell me how to do it? import tkinter.filedialog as filedialog import os import pygame d...
1

votes
1

answer
105

Views

Pause function not working

I'm trying to make a pause function I've tested this pause function separately and it seems to be working fine although there is nothing that it can do at the moment but it still shows. However, when I implement it in my game it doesn't work? I've put it in different places before the while loop an...
1

votes
1

answer
440

Views

How do I delete an image after a collision in pygame?

I'm making a game involving powerups using python. There is a random chance of one spawning and it blits its image on the screen. it picks a random powerup from a list once the player's body (The captain in this scenario) collides with it. I'm checking the collision with a rectangle at the position...
Youssef E.
1

votes
0

answer
238

Views

Python have import pygame but my vs Unable to parse “pyGame”

I have load the pygame,and it can be run well in vs code, but I have wrong in vs, I have checked the environment of python in my vs, and it show that I have surely installed pygame but I just can't run it, and my vs said Unable to parse 'pygame'
c_h_c
1

votes
1

answer
32

Views

Wall sprite not showing up on screen after certain coordinates in pygame

Trying to make collision detection as means to make sprites bounce off one another, but my wall sprites aren't showing up after coords (5, 5) I wasn't sure if maybe it had to do with fill and colorkey both being white, or the fact that pygame.Surface(x, y) is the same as the x, y for the rect. Here...
ajjanna12
1

votes
2

answer
356

Views

Why are my images flickering? (Pygame)

I'm trying to 'animate' a sprite by simply loading a set of 4 images over and over while the assigned left/right buttons are held down. It mostly works, except the images keep flickering and aren't 'switching' as I intended. It also slows down considerably. Being a beginner in Pygame/Python my brain...
Alisha Jain
1

votes
0

answer
49

Views

pygame camera initialization fails with NotImplementedError

On a Linux computer with pygame 1.9.3 I am puzzled by the implementation of the initialization of the pygame camera. The code below demonstrates the surprising behavior: In the first call to Camera (pygame.camera.Camera) the camera will be initialized, while the second call (Camera) raises a NotImpl...
Finn Årup Nielsen
1

votes
0

answer
55

Views

I am trying to code a platformer, but I cant get my my collision detection to work(between my blited character and other rects)

Here is my issue, I can't get my collision detection to work. You can see my attempt down here with the second if statement. The x and y coordinates are the ones for the first rectangle. But this code doesn't work and my character can easily pass through it. How do I get it to work? I want the rect...
Albin Thorn
1

votes
1

answer
69

Views

pygame_sdl2 - app is crashing on mobile during pygame.mouse.get_pressed()

I am developing a game for android with pygame and pygame_sdl2, and rapt for deploy. Currently, the game is at a very first stage of development. I have a joypad draw in the bottom left of my screen, and, when the mouse is pressed in the coordinates of the joypad's buttons, a character is moved acco...
umbe1987
1

votes
0

answer
124

Views

Set input frame rate in pygame.Camera

I am trying to get an input stream from a webcam on OS X self.capture = pygame.camera('/dev/video{}'.format(camera), (640, 480), 'RGB') I get an error (see below), but there are 2 pieces of information that I can not really stitch together. On first sight, it looks like I do not have the correct cam...
Thomas Hubregtsen
1

votes
0

answer
126

Views

pygame.error: display Surface quit

I am creating a python proram where we can play the classical snake xenzia game using our hand gestures and not keyboard. In this as soon as my snake gets hit on the border it the pygame window is destroyed. I then re initialize in the game function but that doesnt seem to do the trick and throws an...
aman
1

votes
0

answer
111

Views

Moving sprites in pygame

I am trying to move a sprite in pygame, I tried to adapt it from a youtube video where he goes through and make a tilebased game, unfortunately it is about 1 - 2 years old so the versions between the modules and python may have changed the functions of some code Here is the code(this is the only rel...
Tudor Popescu
1

votes
0

answer
41

Views

Issues with player input in Pygame

I've recently start using classes in Python (I'm 1000% a rookie) and so far I find it much easier to work with. However, while developing a mini game for my project I've come across the issue of player input. What I have tried should theoretically work, but like I said I am very new to this. import...
Brandon Robinson
1

votes
1

answer
85

Views

Pygame freezes while displaying text

I'm creating the base of a game that will have scrolling text and text wrapping when a line of text goes to far on the screen. Everything works (so far) but at a certain point when using my default_display_text function pygame stops responding. It always stops around the 'broke, slap some fancy word...
TronCrusher
0

votes
0

answer
3

Views

Name Error: global name 'BaseFunction' is not defined

I'm following a pygame tutorial (thenewboston) and I'm having some problem with pyOpenGL. I'm using python 2.7 on anaconda-spyder3.3.4 Here's the code: from OpenGL.GL import * import pygame from pygame.locals import * from OpenGL.GLU import * vertices = ( (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -...
Wannalearnalot
1

votes
1

answer
20

Views

Trying to append objects to a list using MOUSEBUTTONDOWN

Im making a version of boids and im trying to append the boids to a list by using pygames MOUSEBUTTONDOWN fucntion. It works great to some degree. I want it to add one instance of the object, but it adds alot when im left clicking. from precode import * from config import * import pygame as pg from...
Tacey
1

votes
1

answer
44

Views

event inside function not working properly

I have this code that defines a drawScene0 function which is supposed to interact with the user, responding to mouse clicks and keyboard but it doesn't seem to do it it just draws and when i try click or type, it does't work. I tried debugging the events loop inside the drawscene function as well as...
Huzaif Ahmed

View additional questions