我想學習python的pygame庫。Python pygame sprite動畫
我目前正在使用spritesheets學習精靈動畫。我在「javascript」中關注本教程:http://gamedevelopment.tutsplus.com/tutorials/an-introduction-to-spritesheet-animation--gamedev-13099。
我試圖翻譯python的代碼,但它不工作;它只顯示完整的精靈表並且沒有動畫。
這裏是我翻譯的代碼:
import pygame,math
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False
img='jj.png'
class sprites:
def sprite_sheet(self,img,frame_width,frame_height,frame_speed,end_frame):
self.images=pygame.image.load(img)
#calculate number of frames in a row
self.frames_per_row=math.floor(self.images.get_rect().size[0]/frame_width)
self.current_frame=0
self.counter=0
self.frame_speed=frame_speed
self.end_frame=end_frame
def update(self):
if self.counter==self.frame_speed-1:
self.current_frame=(self.current_frame+1) % self.end_frame
self.counter=(self.counter+1) % self.frame_speed
character=sprites()
character.sprite_sheet(img,125,125,3,16)
clock=pygame.time.Clock()
while not done:
#screen.fill((255,255,255))
character.update()
screen.blit(character.images,(30,100))
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
#screen.blit(images,(0,0))#,(current_image*32,0,32,32))
pygame.display.flip()
clock.tick(30)
pygame.quit()
爲什麼它不工作?如何從上面的教程鏈接爲spritesheet製作動畫?