所以首先代碼:馬里奧跨屏跑得太快在pygame的
import pygame, sys
from pygame.locals import *
class Person(pygame.sprite.Sprite):
def __init__(self, screen):
self.screen = screen
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("images/mariowalking0.png")
self.rect = self.image.get_rect()
self.rect.center = (320, 220)
self.poseNumber = 1
def update(self):
self.rect.centerx += 1
if self.rect.centerx > self.screen.get_width():
self.rect.centerx = 0
self.poseNumber = (self.poseNumber + 1)
if self.poseNumber == 2:
self.poseNumber = 0
self.image = pygame.image.load("images/mariowalking" + str(self.poseNumber) +".png")
def main():
screen = pygame.display.set_mode((640, 480))
background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
screen.blit(background, (0, 0))
boy = Person(screen)
allSprites = pygame.sprite.Group(boy)
keepGoing = True
while keepGoing:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False
pygame.quit()
allSprites.clear(screen, background)
allSprites.update()
allSprites.draw(screen)
pygame.display.flip()
if __name__ == "__main__":
main()
如果你想運行的代碼,精靈的圖像可以在這裏找到:http://imgur.com/a/FgfAd
馬里奧Sprite以非常快的速度穿過屏幕。儘管我說我要將centerx的價值增加1.任何想法爲什麼會發生這種情況。
順便說一句我對pygame真的很陌生,所以對不起,如果我忽略了一個明顯的事實或事情。
更新被非常頻繁地調用...在每次翻轉後添加一些毫秒的延遲()...我認爲翻轉比更新() –