Forum >> Programmazione Python >> Videogames >> Pygame Sfondo scorrevole.

Pagina: 1

Pygame Tutorial on how to create sliding backgrounds. Useful for new pygame users.


class Background():

      def __init__(self):

            self.bgimage = pygame.image.load('AnimatedStreet.png')

            self.rectBGimg = self.bgimage.get_rect()

 

            self.bgY1 = 0

            self.bgX1 = 0

 

            self.bgY2 = self.rectBGimg.height

            self.bgX2 = 0

 

            self.moving_speed = 5

         

      def update(self):

        self.bgY1 -= self.moving_speed

        self.bgY2 -= self.moving_speed

        if self.bgY1 <= -self.rectBGimg.height:

            self.bgY1 = self.rectBGimg.height

        if self.bgY2 <= -self.rectBGimg.height:

            self.bgY2 = self.rectBGimg.height

             

      def render(self):

         DISPLAYSURF.blit(self.bgimage, (self.bgX1, self.bgY1))

         DISPLAYSURF.blit(self.bgimage, (self.bgX2, self.bgY2))


fonte - CodersLegacy








--- Ultima modifica di Shadow in data 2020-07-14 10:02:35 ---

--- Ultima modifica di Shadow in data 2020-07-14 10:03:09 ---


Pagina: 1



Esegui il login per scrivere una risposta.