你如何让你的精灵不在屏幕上复制自己?一旦文本出现,你如何让你的精灵消失或重新开始?

所以,我又被卡住了,但是当经过广泛的研究没有任何效果时,我将它用作最后的手段。请不要因为这个而烤我,我是新手。所以,基本上我试图让我的精灵移动 (yoyo),但是随着 yoyo 上下移动,帧会不断复制。所以,我不知道如何解决这个问题。如果悠悠球接触到游戏窗口的边界,它会发生碰撞并显示文本,然后游戏会重新开始。但是,当悠悠球与窗口边框碰撞时,它会重新启动,但卡住的悠悠球仍在显示,并出现一个新的悠悠球。文本显示但不会在 2 秒后消失。


   import pygame

   import time

   pygame.init()


   width = 900

   height = 900

   red = (255,0,0)

   text = "game over"


   screem = pygame.display.set_mode((width,height))


   pygame.display.set_caption("yoyo")

   clock = pygame.time.Clock()


   background = pygame.image.load("room.png").convert()

   win.blit(background, [0,0])


   yoyo= pygame.image.load("yoyo.png").convert()



  def Yoyo (x,y):

    win.blit(yoyo, [x,y])



def mainloop():

   x = 87

   y = 90



yc = 0 



  while True:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            Exit = True

        if event.type == pygame.KEYDOWN:

            if event.key == pygame.K_UP:



    Yoyo(x,y)

    y += yc


    if y > 23 or y < -90:


    pygame.display.update()

    clock.tick(60)


mainloop()

pygame.quit()

quit()



叮当猫咪
浏览 166回答 1
1回答

呼唤远方

在每一帧中重绘整个场景。这意味着您也必须在每一帧中绘制背景。在绘制blit其他任何内容之前,在主循环中绘制 ( ) 背景:while not Exit:&nbsp; &nbsp; for event in pygame.event.get():&nbsp; &nbsp; &nbsp; &nbsp; if event.type == pygame.QUIT:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit = True&nbsp; &nbsp; &nbsp; &nbsp; if event.type == pygame.KEYDOWN:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if event.key == pygame.K_UP:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y_change = -5&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elif event.key == pygame. K_DOWN:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y_change = 5&nbsp; &nbsp; &nbsp; &nbsp; if event.type == pygame.KEYUP:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if event.key == pygame.K_UP or event.key == pygame.K_DOWN:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y_change = 0&nbsp;&nbsp; y += y_change&nbsp; if y > 405 or y < -200:&nbsp; &nbsp; &nbsp; collision()&nbsp; GameLoop()&nbsp;&nbsp; win.blit(bg, [0,0]) # <----- draw background&nbsp; Bee(x,y)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # <----- draw the bee on the background&nbsp; # [...] all further drawing has to be done here&nbsp; pygame.display.update()&nbsp; clock.tick(60)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python