据我所知,这是我在屏幕上显示和图像时应该做的所有事情,但事实并非如此。我知道我必须错过一些相当明显的东西,但我看不出我错过了什么,不让我的图像出现在屏幕上。
main.py
import pygame
from loading import *
from settings import *
class game():
def __init__(self):
self.gameRunning = True
self.screen = pygame.display.set_mode((screen_width, screen_height))
self.clock = pygame.time.Clock()
self.Background_images = load_images()
def gameLoop(self):
self.clock.tick(fps)
self.event()
self.update()
def event(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.gameRunning = False
def update(self):
self.screen.blit(self.Background_images["layer1"], (0,0))
pygame.display.update()
playGame = game()
while playGame.gameRunning == True:
playGame.gameLoop()
loading.py
import pygame
from settings import *
def load_images():
Parallax_images = {}
Parallax_images["layer1"] = pygame.image.load("PARALLAX\layer1.png")
Parallax_images["layer2"] = pygame.image.load("PARALLAX\layer2.png")
Parallax_images["layer3"] = pygame.image.load("PARALLAX\layer3.png")
Parallax_images["layer4"] = pygame.image.load("PARALLAX\layer4.png")
Parallax_images["layer5"] = pygame.image.load("PARALLAX\layer5.png")
Parallax_images["layer6"] = pygame.image.load("PARALLAX\layer6.png")
Parallax_images["layer7"] = pygame.image.load("PARALLAX\layer7.png")
Parallax_images["layer8"] = pygame.image.load("PARALLAX\layer8.png")
return Parallax_images
答案 0 :(得分:0)
这篇文章对于绘制图像非常有用
What is a good way to draw images using pygame?
<强>更新强>
png图像本身似乎有些不对劲。使用不同的图像编译和运行时,代码可以正常工作。