python - Pygame - 即使我正在更新我的图像,也会出现奇怪的踪迹。这是怎么回事?
问题描述
大家好,所以我是 pygame 的新手,我正在尝试做一些相当简单的事情。只需在屏幕上移动图像。我以前做过,没有遇到过这个问题。我所做的唯一更改是我现在将 1 个图像放在另一个图像之上。
出于某种奇怪的原因,这会导致留下痕迹。
我试过清除屏幕并重新绘制,但没有得到积极的结果。
任何帮助,将不胜感激。
def main():
pygame.init()
screen = pygame.display.set_mode((700,680),0,32)
clock = pygame.time.Clock()
bgd_image = pygame.image.load("Grid.png").convert()
#X Motor Pieces
MotorXbase = pygame.image.load("MotorXBase.png").convert()
MotorXbase.set_colorkey((34,177,76))
MotorXMovePiece = pygame.image.load("MotorXMovePiece.png").convert()
MotorXMovePiece.set_colorkey((34,177,76))
#Y Motor Pieces
MotorYbase = pygame.image.load("MotorYBase.png").convert()
MotorYbase.set_colorkey((34,177,76))
MotorYMovePiece = pygame.image.load("MotorYMovePiece.png").convert()
MotorYMovePiece.set_colorkey((34,177,76))
screen.fill([34,177,76])
black = (0,0,0)
running = True
xpos = 16
ypos = 14
xstep = 1
ystep = 1
while running:
screen.blit(bgd_image,(0,0))
screen.blit(MotorXbase, [50,550])
MotorXbase.blit(MotorXMovePiece,[xpos,18])
screen.blit(MotorYbase, [550,50])
MotorYbase.blit(MotorYMovePiece,[20,ypos])
clock.tick(60)
pygame.display.update()
screen.fill(black)
xpos += xstep
ypos += ystep
if xpos >399 or xpos <16:
xstep = -xstep
if ypos > 397 or ypos < 14:
ystep = -ystep
# event handling, gets all event from the eventqueue
for event in pygame.event.get():
# only do something if the event is of type QUIT
if event.type == pygame.QUIT:
# change the value to False, to exit the main loop
running = False
解决方案
来自评论:
好吧,您将片段图像传送到基本图像上,而不是直接到屏幕上。这是一个破坏性操作,您必须保留基本映像的未修改副本,或者从磁盘重新加载它们,以撤消 blit。
推荐阅读
- c# - 如何在 C# 中重新验证模型?
- scala - ScalaTest:在同一毫秒内将 Instant 视为相等
- excel - 使用基于单元格的计算来创建表格
- javascript - ADF如何从bean触发一个clientListener?
- pug - 如何使用 pug 作为 angular-cli 的默认模板引擎?
- powershell - 通过powershell查找对计算机具有管理员访问权限的所有用户的语言无关方式
- azure-ad-b2c - APIM 开发人员门户示例生产站点
- java - Java Selenium 在没有 IDE 的情况下通过命令提示符 CMD Windows 运行
- vim - 如果通过资源管理器地址栏打开'vim',则在 cmd 中无法识别?
- python - Facebook 的 Python Business SDK 使用了一个保留关键字——解决方法?