pygame

Why is my pygame window not opening after I close another window and producing an unexpected error?

和自甴很熟 提交于 2021-02-02 09:56:37
问题 so here is my code: import math import random import time import pygame from pygame import mixer import pygame_functions from pygame_functions import * # Initialises pygame pygame.init() pygame.display.init() #Difficulty num_of_enemies = 0 set_positive_enemyX_change = 0 set_negative_enemyX_change = 0 #Menu def menu(num_of_enemies, set_positive_enemyX_change, set_negative_enemyX_change): screenSize(1000, 1000) # text, fontSize, xpos, ypos, fontColour='black', font='Arial', background='clear'

Why is my pygame window not opening after I close another window and producing an unexpected error?

依然范特西╮ 提交于 2021-02-02 09:55:20
问题 so here is my code: import math import random import time import pygame from pygame import mixer import pygame_functions from pygame_functions import * # Initialises pygame pygame.init() pygame.display.init() #Difficulty num_of_enemies = 0 set_positive_enemyX_change = 0 set_negative_enemyX_change = 0 #Menu def menu(num_of_enemies, set_positive_enemyX_change, set_negative_enemyX_change): screenSize(1000, 1000) # text, fontSize, xpos, ypos, fontColour='black', font='Arial', background='clear'

Set the width and height of a pygame surface

China☆狼群 提交于 2021-02-02 09:53:03
问题 I am creating my own GUI library with pygame . I have a UIComponent class that creates the UI elements. The UI element itself is created through self.image with width and height . The problem with this is that changing the width and height doesn't seem to work. I'm using self.rect.x to modify its coordinates but when I tried using self.rect.width it didn't have an effect. ui_elements = pg.sprite.Group() class UIComponent(pg.sprite.Sprite): def __init__(self, width, height): pg.sprite.Sprite._

Random non overlapping circles(with circle number controlled) in python and pygame

痴心易碎 提交于 2021-02-02 09:52:32
问题 I was writing the code for non overlapping random circles with different radii.I kind of got the deserved, but my 'if' statement that checks overlap or non overlap excludes a number of circles. So, I get lesser number of circles. Here's the code: import pygame import numpy as np pygame.init() display_width = 800 display_height = 500 black = [0, 0, 0] white = [255, 255, 255] red = [255, 0, 0] display_surface = pygame.display.set_mode((display_width, display_height)) clock = pygame.time.Clock()

Pygame image transparency confusion [duplicate]

五迷三道 提交于 2021-02-02 09:51:06
问题 This question already has answers here : How can I make an Image with a transparent Backround in Pygame? (2 answers) How do I blit a PNG with some transparency onto a surface in Pygame? [duplicate] (4 answers) pygame image background does not match main background (1 answer) How to make a surface with a transparent background in pygame (3 answers) Closed 3 months ago . I have read the top 20 posts relating to this issue here, read many examples on Google, tried using .convert() , .convert

Set the width and height of a pygame surface

微笑、不失礼 提交于 2021-02-02 09:49:39
问题 I am creating my own GUI library with pygame . I have a UIComponent class that creates the UI elements. The UI element itself is created through self.image with width and height . The problem with this is that changing the width and height doesn't seem to work. I'm using self.rect.x to modify its coordinates but when I tried using self.rect.width it didn't have an effect. ui_elements = pg.sprite.Group() class UIComponent(pg.sprite.Sprite): def __init__(self, width, height): pg.sprite.Sprite._

Pygame image transparency confusion [duplicate]

荒凉一梦 提交于 2021-02-02 09:48:35
问题 This question already has answers here : How can I make an Image with a transparent Backround in Pygame? (2 answers) How do I blit a PNG with some transparency onto a surface in Pygame? [duplicate] (4 answers) pygame image background does not match main background (1 answer) How to make a surface with a transparent background in pygame (3 answers) Closed 3 months ago . I have read the top 20 posts relating to this issue here, read many examples on Google, tried using .convert() , .convert

Pygame image transparency confusion [duplicate]

人盡茶涼 提交于 2021-02-02 09:47:25
问题 This question already has answers here : How can I make an Image with a transparent Backround in Pygame? (2 answers) How do I blit a PNG with some transparency onto a surface in Pygame? [duplicate] (4 answers) pygame image background does not match main background (1 answer) How to make a surface with a transparent background in pygame (3 answers) Closed 3 months ago . I have read the top 20 posts relating to this issue here, read many examples on Google, tried using .convert() , .convert

How to play random Mp3 files in Pygame

房东的猫 提交于 2021-02-02 09:40:30
问题 hi everyone i'm currently working on a project and i'm stuck with this problem. how can i randomly play Mp3 from one folder using Pygame? here is my code. path = "C:/Users/pc/Desktop/sample_songs/" mixer.init() mixer.music.load(path) mixer.music.play() 回答1: First you have to get a list of all the files which ends with '.mp3' in the directory ( os.listdir , see os): import os path = "C:/Users/pc/Desktop/sample_songs/" all_mp3 = [os.path.join(path, f) for f in os.listdir(path) if f.endswith('

VSCode Intellisense not Working for pygame

爱⌒轻易说出口 提交于 2021-02-02 09:35:56
问题 While coding in pygame, I realised that VSCode was not showing up itellisense for quite some pygame modules, and instead showed those modules as variables. After some digging, I found out that if you do import pygame.display as display , the intellisense show up just fine. Is there anyway I can use intelliense without importing these modules like this? 回答1: 'Autocomplete and IntelliSense' was provided by Python Server. In vscode, basically you can choose 'Jedi' or 'Microsoft', and they are