我想在我的关卡中添加一个与地形而不是屏幕保持一致的网格。我想到的方法是将构成网格的所有线条添加为精灵,并随着地形移动它们,但我不知道如何将线条表示为图像。
我自己尝试过这样做,但没有成功。
编辑:这是我尝试过的
class Grid():
def __init__(self):
self.grid = pygame.Surface(size)
self.grid.set_colorkey((0,0,0))
def draw(self):
# DRAW TILE LINES ----------------------------------------------------------
grid_x = 0
grid_y = 0
for i in range(total_level_width // TILE_SIZE):
pygame.draw.aaline(self.grid,BLACK,[grid_x,0],[grid_x,total_level_height])
pygame.draw.aaline(self.grid,BLACK,[0,grid_x],[total_level_width,grid_y])
grid_x += TILE_SIZE
grid_y += TILE_SIZE
# tile test
pygame.draw.rect(screen,BLACK,(49*TILE_SIZE,34*TILE_SIZE,TILE_SIZE,TILE_SIZE))
screen.blit(self.grid,(0,0))
创建对象:
grid = Grid()
调用类:(在主程序循环中)
grid.draw()