Я пытался создать текстурную игру, но она не работает без ошибок. Я покажу код.
import time
import pygame
from pygame.locals import *
def Main():
pygame.mixer.init()
pygame.mixer.music.load(r"C:\...\OMFG+-+Ice+Cream.mp3")
pygame.mixer.music.play(-1)
pygame.init()
screen = pygame.display.set_mode((640, 480))
screen.fill((0,0,0))
pygame.display.set_caption("3 Minutes Left!!!")
font = pygame.font.Font('freesansbold.ttf', 18)
intro_1 = font.render('3', True, (255,255,255))
intro_2 = font.render('Minutes', True, (255,255,255))
intro_3 = font.render('Left!!!', True, (255,255,255))
time.sleep(1)
screen.blit(intro_1, (140, 30)) #This isn't working.
time.sleep(1)
screen.blit(intro_2, (340, 30)) #This isn't working.
time.sleep(1)
screen.blit(intro_3, (540, 30)) #This isn't working.
Main()
Я думал, что код screen.blit будет работать с циклами while. Я попробовал.
import time
import pygame
from pygame.locals import *
def Main():
pygame.mixer.init()
pygame.mixer.music.load(r"C:\...\OMFG+-+Ice+Cream.mp3")
pygame.mixer.music.play(-1)
pygame.init()
screen = pygame.display.set_mode((640, 480))
screen.fill((0,0,0))
pygame.display.set_caption("3 Minutes Left!!!")
font = pygame.font.Font('freesansbold.ttf', 18)
intro_1 = font.render('3', True, (255,255,255))
intro_2 = font.render('Minutes', True, (255,255,255))
intro_3 = font.render('Left!!!', True, (255,255,255))
while True: #This isn't working.
time.sleep(1)
screen.blit(intro_1, (140, 30)) #This isn't working.
time.sleep(1)
screen.blit(intro_2, (340, 30)) #This isn't working.
time.sleep(1)
screen.blit(intro_3, (540, 30)) #This isn't working.
Main()
И я запустил программу. Но вкладка Pygame не получила ответа. Итак, я попробовал screen.blit в определении.
import time
import pygame
from pygame.locals import *
def Main():
pygame.mixer.init()
pygame.mixer.music.load(r"C:\...\OMFG+-+Ice+Cream.mp3")
pygame.mixer.music.play(-1)
pygame.init()
screen = pygame.display.set_mode((640, 480))
screen.fill((0,0,0))
pygame.display.set_caption("3 Minutes Left!!!")
font = pygame.font.Font('freesansbold.ttf', 18)
intro_1 = font.render('3', True, (255,255,255))
intro_2 = font.render('Minutes', True, (255,255,255))
intro_3 = font.render('Left!!!', True, (255,255,255))
while True: #This isn't working.
screen_blit(screen, intro_1, intro_2, intro_3) #This isn't working.
def screen_blit(screen, intro_1, intro_2, intro_3): #This isn't working.
time.sleep(1)
screen.blit(intro_1, (340, 30)) #This isn't working.
time.sleep(1)
screen.blit(intro_2, (340, 30)) #This isn't working.
time.sleep(1)
screen.blit(intro_3, (340, 30)) #This isn't working.
Main()
Опять нет ответа. Как я могу это исправить ???