pygame

Will converting to PySDL2 make my app run faster than it does under PyGame?

拈花ヽ惹草 提交于 2019-12-25 09:48:48
问题 I've written a little toy in Python using Pygame. It generates critters (a circle with a directional line, not an image) to wander around the screen. I'm interested in making it more sophisticated, but I'm running into serious performance problems. As the number of critters on the screen passes 20, the frame rate drops rapidly from 60fps as far as 11fps with 50 on the screen. I've gone over my (very simple) code a number of different ways, even profiling with cProfile, without finding any way

Will converting to PySDL2 make my app run faster than it does under PyGame?

六眼飞鱼酱① 提交于 2019-12-25 09:48:07
问题 I've written a little toy in Python using Pygame. It generates critters (a circle with a directional line, not an image) to wander around the screen. I'm interested in making it more sophisticated, but I'm running into serious performance problems. As the number of critters on the screen passes 20, the frame rate drops rapidly from 60fps as far as 11fps with 50 on the screen. I've gone over my (very simple) code a number of different ways, even profiling with cProfile, without finding any way

Pygame Get Value of Button

我与影子孤独终老i 提交于 2019-12-25 09:19:44
问题 I've got this problem with Pygame that I cannot seem to find a solution too. I'm trying to use a PS4 controller to control an RC car. I've got connecting to the controller to the program and seeing how many buttons it has, but I'm unable to get the value of a pushed button in a useable form. Basically, I want to be able to get all of the values of the buttons on the controller. When a button is pressed, the program updates the value of that button and allows me to execute code based on the

Inconsistent skybox rendering using different textures in Pygame + PyOpenGL

岁酱吖の 提交于 2019-12-25 09:05:34
问题 Motivated by my incomplete answer to this question, I am implementing a simple skybox in PyOpenGL in accordance with this tutorial, making minor tweaks as needed for OpenGL 2.1/GLSL 120 and python2.7-isms. For the most part, it works successfully, but depending on what six images I pass to my cubemap, the images either end up swapped between a single pair of opposite faces or are randomly rotated ! Below is the main class of this demo: import pygame import sys import time import glob import

Create a playlist using pygame.mixer [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-25 08:47:26
问题 This question already exists : Create a playlist using pygame.mixer Closed 2 years ago . I have been trying to make a simple playlist that plays 3 songs one after the other the code below shows an attempt of that. Rather than playing the first song music1.mp3 it plays the last song music3.mp3 and stops playing. I have tried looking at similar questions but strugling to find a soloution. Please if anyone can help give me some advice or some guidance it will be much appreciated. Mike import

How do I make a text box in pygame? [duplicate]

不羁的心 提交于 2019-12-25 08:46:20
问题 This question already has answers here : How to create a text input box with pygame? (2 answers) Closed 10 months ago . So I’m new with pygame and I was wondering how do you make a basic text box I know you have to create a window as so: import pygame, sys pygame.init() screen= pygame.display.set_mode([800,600]) pygame.display.flip but then I have no idea where to go from there any help much appreciated :) 回答1: PyGame is low-level library and it doesn't have widgets. You can use other modules

Pygame click is too sensitive

跟風遠走 提交于 2019-12-25 07:58:29
问题 I'm making a game and the game has a shop which you can buy tokens and if you click the button to buy them the mouse goes crazy.. This is a function which waits for the mouse click. def button(text, x, y, width, height, inactive_color, active_color, action): cur = pygame.mouse.get_pos() click = pygame.mouse.get_pressed() if x + width > cur[0] > x and y + height > cur[1] > y: pygame.draw.rect(gameDisplay, active_color, (x, y, width, height)) if click[0] == 1: if action == "buy_slowdown":

Making Player Jump in Pygame

↘锁芯ラ 提交于 2019-12-25 07:34:01
问题 I'm making a very simple game using pygame to practice. Im trying to make my "player" jump when spacebar is pressed. Here is the loop code I'm trying: x,y=10,300 movex,movey=0,0 if event.type==KEYDOWN: if event.key==K_LEFT: movex = -0.2 elif event.key==K_RIGHT: movex=+0.2 elif event.key==K_DOWN: movey=+0.2 elif event.key==K_SPACE: movey=-0.4 movey=+0.4 if event.type==KEYUP: if event.key==K_LEFT: movex = 0 elif event.key==K_RIGHT: movex=0 elif event.key==K_DOWN: movey=0 elif event.key==K_SPACE

How to make a character move while key is held down

ぃ、小莉子 提交于 2019-12-25 07:33:32
问题 I'm trying to create a "player" - black square - which moves when you hold down WASD. I tried looking around here, on google and on youtube on how to make this work, but every solution I've tried has the same problem: instead of moving it while I hold down the key, I have to tap the key constantly to make it move in small bits. I've no clue what I'm doing wrong. Here's the code (using python 3.3 - pygame 1.9): import pygame from pygame.locals import * from pygame.time import * import sys

How to Make the Ball Bounce only if it Hits the Paddle in Python, Pygame (Breakout Recreation)

北慕城南 提交于 2019-12-25 07:27:40
问题 can anyone help me with this? i am having trouble making a simple way to detect if a ball hits a paddle and then bounce it by changing the rect_change_y variable. here is code that works but the ball does not interact with paddle or die when it hits the bottom of the game. import pygame black = ( 0, 0, 0) white = ( 255, 255, 255) green = ( 0, 255, 0) red = ( 255, 0, 0) rect_x = 10 rect_y = 250 pad_x = 350 pad_y = 480 ball = 3 rect_change_x = 1 rect_change_y = 1 pad_x_c = 0 pygame.init() size=