python - 图像未显示在 python 3.6.5 的 pygame 中
问题描述
我在 win32 上的 Python 3.6.5 中使用 Pygame,但我的 MarioGround.png 没有出现。我有两张图片,其中一张正在工作,另一张没有。我也没有错误。这是我的完整代码(待处理):
import pygame
pygame.init()
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
blue = (0,0,255)
sky_blue = (0,150,225)
green = (0,255,0)
displayWidth = 800
displayHeight = 600
#Final :- pygame.display.set_mode((1365, 1050))
gameDisplay = pygame.display.set_mode((displayWidth,displayHeight))
pygame.display.set_caption('Super Mario')
clock = pygame.time.Clock()
crashed = False
timeOut = False
Quit = False
#50,75
marioStanding = pygame.image.load('Super_Mario_Standing2.png').convert()
marioStanding = pygame.transform.scale(marioStanding, (displayWidth//16,displayHeight//8))
ground = pygame.image.load('MarioGround.png')
def Stand(mx,my):
gameDisplay.blit(marioStanding,(mx,my))
mx = (displayWidth * 0.45)
my = (displayHeight * 0.8)
def makeGround(gx,gy):
gameDisplay.blit(ground,(gx,gy))
gx = (displayHeight * 0.45)
gy = (displayWidth * 0.8)
while not crashed and not timeOut and not Quit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
Quit = True
print (event)
gameDisplay.fill(sky_blue)
makeGround(gx,gy)
Stand(mx,my)
pygame.display.update()
clock.tick(24)
pygame.quit()
quit()
我的 Super_Mario_Standing2.png 出现了,虽然 MarioGround.png 没有出现。这里是他们两个的链接:MarioGround.png:https ://drive.google.com/open?id=1Jz7zTI5Cukv8fXlmyOEkwJTOTkuxIGUP
Super_Mario_Standing.png:https ://drive.google.com/open?id=1eUDAin-BUUzi6l-DgxHrf9v8JP8kdAPt
谢谢!!!
解决方案
您已经混淆了displayWidth
和displayHeight
变量,这意味着gy
变量是 640(在屏幕下方)。只需交换它们(另外,这里不需要括号):
gx = displayWidth * 0.45
gy = displayHeight * 0.8
推荐阅读
- python - TesseractNotFoundError:两个 docker 容器 python 应用程序(docker-compose)
- ruby - <<- 符号在rails中是什么意思?
- wordpress - 如何在帖子加载到 WordPress 页面之前更新帖子?
- javascript - React.js - 将状态项设置为数组项,在其他状态项中引用,然后在数组项更改时更新状态
- reactjs - 获取 cookie 时反应状态总是落后一步
- c++ - 26 位韦根数有多少种十进制数的可能性?
- google-kubernetes-engine - GKE Ingress 打开端口
- xaml - 带有 xamarin 表单图标的自定义输入框(android,ios)
- python-3.x - 如何使用大熊猫数据帧的标题创建单行熊猫数据帧
- crystal-reports - Crystal Report Split():拆分名称