pygame

Why does my game made with Pygame suddenly lag for a few seconds? [duplicate]

杀马特。学长 韩版系。学妹 提交于 2021-02-02 03:44:05
问题 This question already has an answer here : Lag when win.blit() background pygame (1 answer) Closed 4 months ago . I made a little space invaders game with pygame, I noticed that the game lags for a few seconds periodically. I do not know what the problem is. I am a beginner. Can you tell me why this happens? Is there any fix to this? Also, why does everything slow down once you add the background image in the main game loop? import pygame from pygame import mixer import random import math #

Python Pygame press two direction key and another key to shoot there's no bullet

ぐ巨炮叔叔 提交于 2021-02-02 03:44:05
问题 I am trying to make a ship shoot a bullet, and everything it works as expected except when I press both UP , LEFT and then SPACE . Then there's no bullet being fired. There's no bullet being fired for RIGHT + DOWN + SPACE , UP + LEFT + SPACE either. However, when I press both UP , RIGHT and then SPACE , it workes. In fact, every other direction key LEFT + DOWN , UP + RIGHT , UP + DOWN works with SPACE key. Here's the code: #!/usr/bin/python import sys import pygame class Setting: def __init__

Why does my game made with Pygame suddenly lag for a few seconds? [duplicate]

不羁岁月 提交于 2021-02-02 03:43:42
问题 This question already has an answer here : Lag when win.blit() background pygame (1 answer) Closed 4 months ago . I made a little space invaders game with pygame, I noticed that the game lags for a few seconds periodically. I do not know what the problem is. I am a beginner. Can you tell me why this happens? Is there any fix to this? Also, why does everything slow down once you add the background image in the main game loop? import pygame from pygame import mixer import random import math #

Why does my game made with Pygame suddenly lag for a few seconds? [duplicate]

删除回忆录丶 提交于 2021-02-02 03:43:33
问题 This question already has an answer here : Lag when win.blit() background pygame (1 answer) Closed 4 months ago . I made a little space invaders game with pygame, I noticed that the game lags for a few seconds periodically. I do not know what the problem is. I am a beginner. Can you tell me why this happens? Is there any fix to this? Also, why does everything slow down once you add the background image in the main game loop? import pygame from pygame import mixer import random import math #

How can i reshape an array from (280, 280, 3) to (28, 28, 3)

这一生的挚爱 提交于 2021-02-02 03:41:21
问题 Hi i tried to write a code, where i write a number on the screen with pygame and then a neural Network predicts the number i wrote. My problem is that i trained my neural network with image arrays in a (28, 28, 3). So i tried to reshape my (280, 280, 3) array. but when i do so my array is None. I use Python 3.7 string_image = pygame.image.tostring(screen, 'RGB') temp_surf = pygame.image.fromstring(string_image, (280, 280), 'RGB') array = pygame.surfarray.array3d(temp_surf) array = array

Why is this pygame program not working so when I hover over the computer screen it turns blue?

房东的猫 提交于 2021-02-01 05:20:54
问题 Hello I am quite new to pygame and I am trying to make an intro for a game where the user hovers over the computer screen and the screen then turns blue so indicate that when you press it the game will start. However, the blue rect simply isn't showing up? By the way, the introScreen is a like a gif but constructed from many different frames. This is my code: import pygame import pygame.gfxdraw import threading pygame.init() width = 800 height = 600 fps = 30 clock = pygame.time.Clock() white

why is the exit window button work but the exit button in the game does not work?

跟風遠走 提交于 2021-02-01 05:16:33
问题 i'm making a start menu for my game but when i hit the exit button i made in the start menu, it doesn't exit. Is there anything wrong with my code? I tried making a function for the exit, put it in the code that exit the game with the window exit button, but nothing worked. import pygame import os pygame.mixer.pre_init() pygame.mixer.init(44100, 16, 2, 262144) pygame.init() from pygame.locals import* pygame.mixer.music.load(os.path.join(os.getcwd(), 'Sounds', 'intro.ogg')) pygame.mixer.music

Why is this pygame program not working so when I hover over the computer screen it turns blue?

一个人想着一个人 提交于 2021-02-01 05:15:28
问题 Hello I am quite new to pygame and I am trying to make an intro for a game where the user hovers over the computer screen and the screen then turns blue so indicate that when you press it the game will start. However, the blue rect simply isn't showing up? By the way, the introScreen is a like a gif but constructed from many different frames. This is my code: import pygame import pygame.gfxdraw import threading pygame.init() width = 800 height = 600 fps = 30 clock = pygame.time.Clock() white

How to implement barriers to stop the player moving through walls

断了今生、忘了曾经 提交于 2021-01-31 07:25:21
问题 Quick note. This is for my A-Level NEA Programming Project. There are two main sections - One where a maze is generated and the user must navigate through it in a given time period, the time period is not currently implemented, and a second section where the user has to answer educational physics questions in order to get the best score. Questions are imported from a text file stored locally on my system. The user's score is then exported to a local text file along with the date completed. So

How do you get pygame to give warning when player touches side of screen?

浪尽此生 提交于 2021-01-31 07:24:28
问题 I created a game using pygame, and I wanted to get pygame to give an error like "You can't touch the screen sides", when player touches screen side. I tried searching on the internet, but I didn't find any good results. I thought of adding a block off the screen and when the player touches the block, it gives warning but that took way to long and anyways didn't work. I also don't know how to give alert, and then after giving the alert, to get the game started again. Does anyone know how to do