背景流动
Posted huweitao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了背景流动相关的知识,希望对你有一定的参考价值。
import pygame from pygame.locals import * import sys class Basesprits( pygame.sprite.Sprite): def __init__(self,image,speed): super(Basesprits,self).__init__() self.image = pygame.image.load(image) self.rect = self.image.get_rect() self.speed = speed def update(self): self.rect.y += self.speed class Backbround(Basesprits): def __init__(self,image,speed,pos = True ): super(Backbround,self ).__init__(image,speed) if pos == False : self.rect.y == -self.rect.y def update(self): super(Backbround ,self ).update() if self.rect.y == 800: self.rect.y = -self.rect.y class Game(object): def __init__(self): self.window = pygame.display.set_mode((470,600)) pygame.display.set_caption(‘@@@‘) self.clock = pygame.time.Clock() self.__create_sprites() def startgame(self): while True: self.get_event() self.showspirts() self.clock.tick(60) pygame.display.update() def get_event(self): for event in pygame.event.get(): if event.type == QUIT: sys.exit() def __create_sprites(self): # 创建精灵 image = Backbround(‘./images/background.png‘, speed=1) image1 = Backbround(‘./images/background.png‘, speed=1, pos=False) self.bg_group = pygame.sprite.Group(image, image1) def showspirts(self): self.bg_group.update() self.bg_group.draw(self.window ) game = Game() game.startgame()
以上是关于背景流动的主要内容,如果未能解决你的问题,请参考以下文章