pygame

How to remove/replace text in pygame

僤鯓⒐⒋嵵緔 提交于 2019-12-18 05:03:08
问题 I'm fairly new to pygame and ive hit my first stump which I cannot find an answer for.. After blitting text, then changing the string for the same variable, the game instead of replacing the original text with the new, overlaps the two texts..? 回答1: You have to erase the old text first. Surfaces created by Font.render are ordinary surfaces. Once a Surface is blit, its contents become part of the destination surface, and you have to manipulate the destination surface to erase whatever was blit

Add pygame module in PyCharm IDE

柔情痞子 提交于 2019-12-18 04:37:08
问题 I've downloaded pygame-1.9.1release.tar.gz from the Pygame website. I extracted and installed it and it's working fine in the command line Python interpreter in Terminal (Ubuntu). But I want to install it for some IDE, like PyCharm. How can I do it? 回答1: Well, you don't have to download it for PyCharm here. You probably know how it checks your code. Through the interpreter! You don't need to use complex command lines or anything like that. You need to is: Download the appropriate interpreter

play music using pygame but no sound

扶醉桌前 提交于 2019-12-18 04:12:11
问题 import pygame pygame.mixer.init() pygame.mixer.music.load("only one.mp3") pygame.mixer.music.play(0) while pygame.mixer.music.get_busy(): pygame.time.Clock().tick(10) When I run the code, there's no sound and the program ends in like a second. Initially I didn't have the while loop until I saw the suggestions in the answers to similar questions. The program does enter the while loop on my friend's windows system, but not on my mac, and it doesn't have any sound either even on my friend's

How to identify which button is being pressed on PS4 controller using pygame

瘦欲@ 提交于 2019-12-18 03:01:48
问题 I am using a Raspberry Pi 3 to control a robotic vehicle. I have successfully linked my PS4 controller to the RPi using ds4drv . I have the following code working and outputting "Button Pressed"/"Button Released" when a button is pressed/released on the PS4 controller using pygame . I am wondering how to identify which button is exactly being pressed. ps4_controller.py import pygame pygame.init() j = pygame.joystick.Joystick(0) j.init() try: while True: events = pygame.event.get() for event

Why are my pygame images not loading?

跟風遠走 提交于 2019-12-17 22:59:21
问题 I found a tutorial online (on Youtube) and it showed me the basics of creating a game with pygame. i found images of the kind he said and what he had. he didn't say where to save them to, i think that may be my problem. here, this is an example of what i have in my program and what shows up on the error bif="bg.jpg" mif="images.png" import pygame, sys from pygame.locals import * pygame.init() screen=pygame.display.set_mode((420,315),0,32) backround=pygame.image.load(bif).convert() mouse_c

Convert a string to a tuple [duplicate]

被刻印的时光 ゝ 提交于 2019-12-17 21:22:06
问题 This question already has answers here : Parse a tuple from a string? (4 answers) Closed 2 years ago . I read some tuple data from a file. The tuples are in string form, for example Color["RED"] = '(255,0,0)' . How can I convert these strings into actual tuples? I want to use this data in PyGame like this: gameDisplay.fill(Color["RED"]) # but it doesn't have the right data right now: gameDisplay.fill('(255,0,0)') 回答1: You could use the literal_eval of the ast module: ast. literal_eval ( node

pygame crashes when fill(color) method is used

元气小坏坏 提交于 2019-12-17 20:53:19
问题 My pygame code crashes somehow when I use the fill() method. First off I found there is an exact same question on this website by some one else who probably watched the same pygame tutorial as I did, but the problem is not actually solved on there and that's why I'm creating this duplicate question (not really a duplicate since the original question asked by someone else wasn't solved either). My code is down below. The part of code that is causing the crashing is the GameDisplay.fill(black)

How do I add jumping to my game

三世轮回 提交于 2019-12-17 20:42:21
问题 import pygame import time pygame.init() display_width = (1000) display_height = (480) black = (255,50,0) white = (0,60,7) blue = (0,205,205) kled1_width = 30 kled1_height = 45 ground1_height = 300 screen = pygame.display.set_mode((display_width,display_height)) pygame.display.set_caption(" kled ") clock = pygame.time.Clock() gameDisplay = screen kled1IMG = pygame.image.load("IMG.png") def kled1(x,y): gameDisplay.blit(kled1IMG,(x,y)) def game_loop(): x = (1) y = (340) x_change = 0 y_change = 0

pip install is not working

坚强是说给别人听的谎言 提交于 2019-12-17 20:31:39
问题 I am trying to install pygame with pip install . but every time i tried i faced to this error. Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))': /simple/pygame-1-9-3-cp36-cp36m-win-amd64/ Retrying (Retry(total=3, connect=None, read=None, redirect=None))

PyGame Collision?

半城伤御伤魂 提交于 2019-12-17 20:10:35
问题 How do I find collisions between characters and images within PyGame? I have drawn a player from an image, and have drawn the walls from tiles, so how would I detect these collisions? 回答1: If you use the pygame Rect class to represent the boundaries of your object, you can detect whether two are colliding by using the Rect.colliderect function. For example: import pygame a = pygame.Rect((1, 1), (2, 2)) b = pygame.Rect((0, 0), (2, 2)) c = pygame.Rect((0, 0), (1, 1)) a.colliderect(b) # 1 a