[英]Still getting a black screen in pygame console while executing code
Before posting this question I have read several other questions here in Stack but none of them seems to relate with my issue. 在发布此问题之前,我已经在Stack中阅读了其他几个问题,但是似乎都与我的问题无关。 Also I have read my code for hours trying to fix it but nothing. 另外,我已经阅读了数小时试图修复它的代码,但一无所获。
I really want to know what is wrong with my code and why I am still getting that black screen when I am executing the pygame code. 我真的很想知道我的代码有什么问题,为什么在执行pygame代码时仍然出现黑屏。
Here is the code: 这是代码:
import pygame,sys
from pygame.locals import *
from random import randint
pygame.init()
ventana = pygame.display.set_mode((1000,1000))
#abajo se encuentra el fondo de la ventana
#ventana.fill(ColorDos)
pygame.display.set_caption("Retouch")
Mi_imagen = pygame.image.load("Image/meflag.png")
Imagen_Dos = pygame.image.load("Image/Kool-Aid.gif")
posX= randint (100, 300)
posY = randint (101, 200)
velocidad=4
Color = (66, 133 ,244)#Azul
ColorDos = pygame.Color(244, 180, 0)#Amarillo
ColorTres = (244,67,54)#Rojo
ColorCuatro = (0,135,68) #verde
derecha=True
rectangulo = pygame.Rect(0,0,100,50)
print posY, posX
# Color = (244,180,0)
#primero donde, despues, color(tupla u objeto), tupla de cordenadas en X, Y. El ultimo parametro es el tamano del radio.
pygame.draw.circle(ventana, Color, (200, 300), 500)
"""Primero donde, despues que color, despues tupla con cuatro valores.
Los primeros dos valores (X,Y) son la esquina izquierda superior.
El tercer valor es el ancho de nuestro rectangulo.
Y el cuarto valor es el alto del rectangulo:"""
pygame.draw.rect(ventana, ColorCuatro,(100,100,100,50) )
"""Primero donde, despues color, despues el tercer parametro es una tupla con tuplas dentro de esta.
Dentro de esa tupla se encuentras las cordenadas, posiciones (X,Y) de los puntos que al final pygame une."""
pygame.draw.polygon(ventana, ColorTres, ((80,90),(200,400), (80,10)) )
while True:
ventana.fill(ColorDos)
# ventana.blit(Mi_imagen,(posX, posY))
ventana.blit(Imagen_Dos,(posX, posY))
pygame.draw.rect(ventana, ColorTres,rectangulo)
rectangulo.left, rectangulo.top = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
"""Este de abajo mueve a Kool-Aid"""
# posX,posY=pygame.mouse.get_pos()
# posX=posX-100
# posY=posY-50
"""Lo de abajo(comentado) mueve la imagen sin parar"""
if derecha==True:
if posX <400:
posX+=velocidad
else:
derecha=False
else:
if posX>1:
posX-=velocidad
else:
derecha=True
# elif event.type == pygame.KEYDOWN:
# if event.key == K_LEFT:
# posX-=velocidad
# elif event.key == K_RIGHT:
# posX+=velocidad
pygame.display.update()
How can I avoid this the next time? 下次如何避免这种情况?
You have wrong indentations and update()
is not inside while True
loop - so you don't send data from buffer to video card and on the screen while True
循环时,您的缩进错误并且update()
不在内部-因此,您不会将数据从缓冲区发送到视频卡,也不会在屏幕上发送
while True:
ventana.fill(ColorDos)
# ventana.blit(Mi_imagen,(posX, posY))
ventana.blit(Imagen_Dos,(posX, posY))
pygame.draw.rect(ventana, ColorTres,rectangulo)
rectangulo.left, rectangulo.top = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
"""Este de abajo mueve a Kool-Aid"""
# posX,posY=pygame.mouse.get_pos()
# posX=posX-100
# posY=posY-50
"""Lo de abajo(comentado) mueve la imagen sin parar"""
if derecha==True:
if posX <400:
posX+=velocidad
else:
derecha=False
else:
if posX>1:
posX-=velocidad
else:
derecha=True
# elif event.type == pygame.KEYDOWN:
# if event.key == K_LEFT:
# posX-=velocidad
# elif event.key == K_RIGHT:
# posX+=velocidad
pygame.display.update()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.