python - blit:不能显示多个精灵
问题描述
我用 Tiled 创建了一张地图,但现在我在 pygame 上正确显示它时遇到了问题。它只显示一个精灵(用grass.png 填充整个屏幕)。
pygame.init()
tilemap = Tilemap({
# Load the textures
0: pygame.image.load("grass.png"),
1: pygame.image.load("water.png")},
100, # Tile size
10, # Width
10, # Height
2) # Border size (default is 0)
DISPLAYSURF = pygame.display.set_mode(tilemap.window_size)
tilemap.read_csv('Mappa.csv')
tilemap.draw(DISPLAYSURF) # Draw the map
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
从班级:
class Tilemap:
tilemap = []
def __init__(self, textures, tilesize, width, height, borders=0):
self.textures = textures # List of textures in dictionary format
self.tilesize = tilesize + borders # The size of a tile
self.width = width # How many tiles wide the map is
self.height = height # How many tile high the map is
self.window_size = [self.tilesize*self.width-borders,
self.tilesize*self.height-borders]
self.mapsize = [self.width, self.height]
self.borders = borders
def read_csv(self, filename):
with open(os.path.join(filename)) as data:
data = csv.reader(data, delimiter=',')
for row in data:
self.tilemap.append(list(row))
return self.tilemap
def draw(self, display):
for row in range( self.tilesize -self.borders ):
for column in range( self.tilesize -self.borders ):
Texture = int(self.tilemap[row][column])
display.blit(self.textures[Texture],
(column*self.tilesize, row*self.tilesize))
草纹理
水纹理
它应该做这样的事情:
但最终的结果只是草:
解决方案
推荐阅读
- javascript - 使用JavaScript点击后如何再次重置随机生成的数字?
- iphone - 消息事件在 Chat_SDK 中多次触发
- python - Django获取相关对象维护查询集中父级的顺序并获取下一个对象
- regex - 用于匹配不能包含某些字符或子字符串的字符串的正则表达式
- python - python中列表列表中的唯一列表
- laravel - Laravel Sanctum Nuxt 用户注册错误
- laravel - Laravel 查询在生产中失败
- python - 如何在不使用 conda 环境的情况下在 python 中添加 tkinter h
- c++ - Switch中使用devkit pro的简单SDL2 c ++程序无法在模拟器中启动
- html - 选择另一个元素时 CSS 悬停将不起作用