1
我目前正在做一個側面滾動遊戲。我畫了一個簡單的圖形,並畫出了他的動畫,當'W'鍵被幫助下來時,他的動畫正確。問題是我不知道如何讓原始繪圖(他仍然握着的那個繪圖)在我按住W的時候消失,因此它們彼此重疊。這裏是我的代碼:動畫幫助,Python 3.2與Pygame
def pulse_ninja(screen,x,y):
#Head
pygame.draw.ellipse(screen,PULSEPURPLE,[14+x,-8+y,15,15],0)
#Legs
pygame.draw.line(screen,WHITE,[20+x,17+y],[25+x,27+y],4)
pygame.draw.line(screen,WHITE,[20+x,17+y],[15+x,27+y],4)
#Body
pygame.draw.line(screen,PULSEPURPLE,[20+x,16+y],[20+x,-2+y],4)
#Arms
pygame.draw.line(screen,PULSEPURPLE,[20+x,3+y],[30+x,18+y],4)
pygame.draw.line(screen,PULSEPURPLE,[20+x,3+y],[10+x,18+y],4)
#Sword
if event.type == pygame.KEYUP:
if event.key == pygame.K_w:
pygame.draw.line(screen,GREEN,[30+x,18+y],[35+x,0+y],3)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_w:
pygame.draw.line(screen,GREEN,[30+x,18+y],[50+x,16+y],3)
def ninja_animate_right(screen,x,y):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_d:
# Head
pygame.draw.ellipse(screen,PULSEPURPLE,[16+x,-6+y,15,15],0)
# Legs
pygame.draw.arc(screen,WHITE,[10+x,0+y,15,30], 3*pi/2, 2*pi, 2)
#pygame.draw.arc(screen,WHITE,[20+x,17+y],[15+x,27+y],4)
# Body
pygame.draw.line(screen,PULSEPURPLE,[20+x,16+y],[25+x,-2+y],4)
# Arms
pygame.draw.line(screen,PULSEPURPLE,[20+x,3+y],[30+x,18+y],4)
pygame.draw.line(screen,PULSEPURPLE,[20+x,3+y],[10+x,18+y],4)
if event.type == pygame.KEYUP:
if event.key == pygame.K_w:
pygame.draw.line(screen,GREEN,[30+x,18+y],[35+x,0+y],3)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_w:
pygame.draw.line(screen,GREEN,[30+x,18+y],[50+x,16+y],3)
,當我打電話給他們我只是讓他們陸續
pulse_ninja(screen,x,y)
ninja_animate_right(screen,x,y)
我猜我需要一個while循環一行?有停止模塊嗎?假設我想運行一個函數,然後在條件滿足後停止它。這基本上就是我想要做的。
謝謝,我還沒有完全理解課程,但我現在正在研究它們。這幫了很多。 –