pygame

How can I create a text input box with Pygame?

十年热恋 提交于 2021-02-17 05:23:32
问题 I want to get some text input from the user in Python and display what they are typing in a text box, and when they press enter, it gets stored in a string. I've looked everywhere, but I just can't find anything. I'm using Pygame. 回答1: You can define a rect as the area of the input box. If a pygame.MOUSEBUTTONDOWN event occurs, use the colliderect method of the input_box rect to check if it collides with the event.pos and then activate it by setting a active variable to True . If the box is

pygame.error:video system not initialized

北城余情 提交于 2021-02-17 05:22:19
问题 So i wrote this code: # Pygame development 4 # Focus on making code object oriented # Introduce classes and objects into our code # Gain access to the pygame library import pygame # Size of the screen SCREEN_TITLE = 'Crossy RPG' SCREEN_WIDTH = 500 SCREEN_HEIGHT = 500 # Colors according to RGB codes WHITE_COLOR = (255, 255, 255) BLACK_COLOR = (0, 0 , 0) # Clock used to update game events and frames clock = pygame.time.Clock() pygame.font.init() font = pygame.font.SysFont('comicsans', 75) class

How to ask 20 multiple choice questions on pygame?

微笑、不失礼 提交于 2021-02-17 05:07:37
问题 I am coding a very basic game on pygame for a project and the main function of the game is to ask 20 questions based on which operator(s) and level the user has picked to play the game at. I am really struggling with two things: the first being that the code which I have written does produce 20 questions with the correct operator and level of difficulty however I don't know how to blit these to the screen one at a time each time the user has answered the last one. Currently, the code only

Rendering text in pygame causes lag

徘徊边缘 提交于 2021-02-17 04:57:07
问题 I have write function in my functions module which looks like this def write(size, writing, color, x, y): font = pygame.font.SysFont("corbel", size) text = font.render(writing, True, color) D.blit(text, (x, y)) I imported this to my main module and created a function as follows in the main module def print_stats(): write(30, f"Red player's hp {player2.hp}", (200, 50, 50),10, 10) write(30, f"Green player's hp {player1.hp}", (50, 200, 50),10, 60) As long as i dont put print_stats() in the main

TypeError: 'pygame.Surface' object is not callable and pygame window crashes

送分小仙女□ 提交于 2021-02-17 02:43:00
问题 I'm quite new to Pygame and Python and I've just made one of my first codes but somehow I keep getting this error: TypeError: 'pygame.Surface' object is not callable I don't know whether there is something wrong in the code or just because Pygame/Python isn't installed correctly. bif="bg.jpg" mif="ball.png" import pygame, sys from pygame.locals import * pygame.init() screen=pygame.display.set_mode((640,360),0,32) background=pygame.image.load(bif).convert() mouse_c=pygame.image.load(mif)

Dragging object along x-axis in pygame

南楼画角 提交于 2021-02-17 02:06:39
问题 I want to be able to drag the blue object along the x-axis (black line) using mouse so that it does not move in y-direction. When I try to drag it, nothing happens. Where is the problem? import pygame def initialize(): pygame.init() global height, width height = 600 width = 900 screen = pygame.display.set_mode((width, height)) screen.fill((255, 255, 255)) pygame.draw.line(screen, (0, 0 ,0), (0, height / 2), (width, height / 2), 3) return screen def object(): dragging = False object_1 = pygame

Dragging object along x-axis in pygame

試著忘記壹切 提交于 2021-02-17 02:06:26
问题 I want to be able to drag the blue object along the x-axis (black line) using mouse so that it does not move in y-direction. When I try to drag it, nothing happens. Where is the problem? import pygame def initialize(): pygame.init() global height, width height = 600 width = 900 screen = pygame.display.set_mode((width, height)) screen.fill((255, 255, 255)) pygame.draw.line(screen, (0, 0 ,0), (0, height / 2), (width, height / 2), 3) return screen def object(): dragging = False object_1 = pygame

Pygame OpenGL 3D Cube Lag

无人久伴 提交于 2021-02-17 02:06:24
问题 I am following a tutorial series that is rather old on pyOpenGL and I am doing exactly as he does. However I am experiencing lag - I have AMD FX-6300 with 8gb ram, GTX-1050ti and files are stored on a flashdrive. I have read some places that using glBegin and glEnd cause issues? What should I use instead and how would I do it in this code: import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * import random """ - A Cube has 8 Nodes/Verticies - 12 Lines

Pygame OpenGL 3D Cube Lag

元气小坏坏 提交于 2021-02-17 02:06:24
问题 I am following a tutorial series that is rather old on pyOpenGL and I am doing exactly as he does. However I am experiencing lag - I have AMD FX-6300 with 8gb ram, GTX-1050ti and files are stored on a flashdrive. I have read some places that using glBegin and glEnd cause issues? What should I use instead and how would I do it in this code: import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * import random """ - A Cube has 8 Nodes/Verticies - 12 Lines

Dragging object along x-axis in pygame

核能气质少年 提交于 2021-02-17 02:06:19
问题 I want to be able to drag the blue object along the x-axis (black line) using mouse so that it does not move in y-direction. When I try to drag it, nothing happens. Where is the problem? import pygame def initialize(): pygame.init() global height, width height = 600 width = 900 screen = pygame.display.set_mode((width, height)) screen.fill((255, 255, 255)) pygame.draw.line(screen, (0, 0 ,0), (0, height / 2), (width, height / 2), 3) return screen def object(): dragging = False object_1 = pygame