大家好,所以我是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
答案 0 :(得分:0)
来自评论:
好吧,您将片断图像传输到基本图像上,而不是直接传输到屏幕上。这是一个破坏性操作,您必须保留基本图像的未修改副本,或从磁盘重新加载它们,以撤消 blit。