【发布时间】:2014-01-13 00:08:32
【问题描述】:
我正在使用surface.fill(color, rect) 在精灵表面上绘制一个彩色小方块,然后按以下顺序显示在其他表面之上:
- 背景表面
- 迷宫表面
- 精灵表面
目前我遇到了一个问题,我的精灵在屏幕上涂抹,因为我没有每次都擦拭屏幕。 如何消除这种拖尾效果,同时防止精灵图层覆盖其他图层?
图层代码 - 已初始化,但未更新每一帧。
game_surface = pygame.Surface((self.canvas.get_size()))
game_surface = game_surface.convert()
game_surface.fill((0,0,255))
maze_surface = pygame.Surface((self.canvas.get_size()))
maze_surface = maze_surface.convert_alpha()
maze_surface.fill((0,0,255,0))
play_surface = pygame.Surface((self.canvas.get_size()))
play_surface = play_surface.convert_alpha()
play_surface.fill((0,0,0,0))
目前只有play_surface 实际使用透明度,但最终play_surface 和maze_surface 都需要是透明的。
精灵图层更新 - 每次移动精灵时调用。
def update(self, canvas):
# move sprite if keys pressed (not shown)
self.surface.fill((0,0,0,0)) # Newest screen fill attempt. Causes smearing effect
self.surface.fill(self.color, self.rect) # draw green square
canvas.blit(self.surface, (0,0))
涂抹效果:红色 = maze_layer,绿色 = 涂抹精灵
Alternate sprite fill - 以上的修改版本
def update(self, canvas):
# move sprite if keys pressed (not shown)
self.surface.fill((0,0,0)) # Original screen fill. Covers up lower layers
self.surface.fill(self.color, self.rect) # draw green square
canvas.blit(self.surface, (0,0))
不透明 - 黑色 = 填充颜色(我想这样做而不覆盖其他图层)
我怎样才能消除这种拖尾效应(图 1),同时防止精灵层覆盖其他层(图 2)?非常感谢任何帮助。
【问题讨论】: