所以我试着开始使用Pygame,但是我在网上找到的所有教程都只使用了一个文件。我反复思考如何在一个函数中加载所有图像。决定把它们保存在字典里。问题是,当我试图从字典中粘贴图像时,我得到以下错误:
Traceback (most recent call last):
File "J:\Growth of Deities\Main.py", line 32, in <module>
pygame.Surface.blit(Sprites["TileWastelandBasic"], (0, 0))
TypeError: argument 1 must be pygame.Surface, not tuple
所以我花了一点时间在google上搜索了一个小时左右的代码,但我不明白为什么会出错。我想是因为我不能在字典里保存图像,但我不确定。有人知道怎么修理吗?在
我的主文件: 导入pygame 从启动导入LoadTextures 游戏机初始化()
^{pr2}$我的图像加载文件:
import pygame
import os, sys
def Load():
Sprites = {}
WastelandSprites = 'Assets\Textures\Tile Sprites\Wasteland'
Sprites["TileWastelandBasic"] = pygame.image.load(os.path.join(WastelandSprites + "\WastelandBasic.png")).convert_alpha()
Sprites["TileWastelandBasic"] = pygame.transform.scale(Sprites["TileWastelandBasic"], (50, 50)).convert_alpha()
return Sprites
问题不是因为你的字典。blit的签名是
其中
^{pr2}$source
必须是曲面。但是,这假设blit
是用一个游戏。表面实例作为接收器。相反,您将从其类调用blit
函数,这意味着它的签名是有效的其中
self
也必须是曲面。您可以通过将呼叫更改为来解决您的问题但我建议你用更地道的
相反。在
参见:http://www.pygame.org/docs/ref/surface.html#pygame.Surface.blit
相关问题 更多 >
编程相关推荐