pygame

Python 3 non-blocking synchronous behavior

青春壹個敷衍的年華 提交于 2021-02-05 06:01:23
问题 I'm making the classic atari snake game in python3 using Pygame. I want to spawn a subprocess to listen for key strokes so that whenever the player enters a key (UP, DOWN, LEFT, or RIGHT), the subprocess sends the parent process the key. But this pipe should not be blocking, so that the snake can travel in the direction it was traveling until the key is received. I found Python's official documentation on multi-processes, but it does not describe the behavior I want, or at least doesn't

Pygame: Display not updating until after delay

前提是你 提交于 2021-02-05 04:59:19
问题 I have a bug in the program I am writing where I first call: pygame.display.update() Then I call: pygame.time.wait(5000) I want the program to update the display and then wait for a set period of time before continuing. However for some reason the display only updates after the waiting time, not before. I have attached some example code to demonstrate what is happening: import pygame pygame.init() white = (255,255,255) black = (0,0,0) green = (0,255,0) screenSize = screenWidth, screenHeight =

Why do I keep getting a positional argument error?

折月煮酒 提交于 2021-02-04 21:01:23
问题 Can someone please explain to me why I keep getting this error: TypeError: get_n_nouns() takes 1 positional argument but 2 were given . I have already had a look at where my problem may be by looking at a similar question (Link) But I have adapted my code going along with the answer and yet I end up with the above error. Here is the error in full: Traceback (most recent call last): File "C:/Users/...../Downloads/Comp4.1/trialTo3.py", line 21, in <module> app.createPhrases() File "C:/Users/...

Why do I keep getting a positional argument error?

偶尔善良 提交于 2021-02-04 21:00:23
问题 Can someone please explain to me why I keep getting this error: TypeError: get_n_nouns() takes 1 positional argument but 2 were given . I have already had a look at where my problem may be by looking at a similar question (Link) But I have adapted my code going along with the answer and yet I end up with the above error. Here is the error in full: Traceback (most recent call last): File "C:/Users/...../Downloads/Comp4.1/trialTo3.py", line 21, in <module> app.createPhrases() File "C:/Users/...

Python py2exe all-in-one

跟風遠走 提交于 2021-02-04 18:39:30
问题 I'm very new to python, and I wanted to compile my code into a .exe for everyone to be able to use. I create the .exe without a problem, but instead of it being in an "all-in-one" sort of file, I get a folder that looks like this: http://i.stack.imgur.com/gi2kK.png I tried pygame2.exe (provided courtesy of pygame, since this game was made in pygame) but I get an error when I use the pre-made script from them (something about a build_exe error). Anyways, is there a way that I can combine all

Pygame window not receiving keyboard events on Mac

女生的网名这么多〃 提交于 2021-02-04 16:16:28
问题 I am running this very simple tutorial on Pygame: https://www.youtube.com/watch?v=xh4SV3kF-zk I can't get keyboard events to be recognised by the game window. I have read a number of similar questions about this, but the answers don't seem right for Macs. I am using miniconda and it might be that I need to quit the virtualenvironment? I don't understand how to do that tho. Or maybe I need to set the focus to my window - but I don't know how to do that either. This must be an issue lots of

How to render/blit text in pygame for good performance

…衆ロ難τιáo~ 提交于 2021-02-04 08:20:10
问题 I am working on a small game (as a hobby) using Pygame. Before this I never worked on graphical interfaces and I am encountering some performance issues. Even in the options menu the FPS seem to be capped at around 110, which maybe doesn't sound that bad, but considering it is just a black screen with some text on it the FPS definitely should be higher. This is the code for one of the textboxes: font = pygame.font.SysFont("Comic Sans MS", 180) color = (0,60,20) screen.blit(font.render("Title"

Image loading using pygame

本秂侑毒 提交于 2021-02-04 08:19:12
问题 This is the code for my background grid Background = pygame.display.set_mode((900 ,900)) Green = (45,198,14) Background.fill(Green) for i in range(0, 900, 50): pygame.draw.line(Background, (0, 0, 0), (0, i), (900, i)) pygame.draw.line(Background, (0, 0, 0), (i, 0), (i, 900)) pygame.display.update() while pygame.event.wait().type != pygame.QUIT: pass I can not get any images to load onto it would i have to convert this into n image and then a sprite or is there a way for me to load images onto

Image loading using pygame

微笑、不失礼 提交于 2021-02-04 08:18:08
问题 This is the code for my background grid Background = pygame.display.set_mode((900 ,900)) Green = (45,198,14) Background.fill(Green) for i in range(0, 900, 50): pygame.draw.line(Background, (0, 0, 0), (0, i), (900, i)) pygame.draw.line(Background, (0, 0, 0), (i, 0), (i, 900)) pygame.display.update() while pygame.event.wait().type != pygame.QUIT: pass I can not get any images to load onto it would i have to convert this into n image and then a sprite or is there a way for me to load images onto

Pygame Window not Responding after few seconds

做~自己de王妃 提交于 2021-02-04 08:14:14
问题 The below code makes the window not respond when started.. I wanted to make hangman game and I got the logic done and I was just trying to make the window pop up and its not responding. Also when I run the program, when I type in the letter and type another one then it erases the previous letter a writes the new letter with the underscores. How can I make it so that it keeps the previous letter and prints it with the new letter? import pygame pygame.init() running = True window_width = 600