-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.py
More file actions
21 lines (17 loc) · 1011 Bytes
/
background.py
File metadata and controls
21 lines (17 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import pygame
class Background:
def __init__(self, window_width, window_height, scroll_speed):
self.image = pygame.image.load("sprites/background/background.png") #Carga la imagen
self.image = pygame.transform.scale(self.image, (window_width, window_height)) #Hace la imagen el tamaño de la pantalla
self.width = window_width #Tamaño del ancho de la pantalla que tendrá el background
self.height = window_height #Tamaño de la altura de la pantalla que tendrá el background
self.scroll_speed = scroll_speed #Velocidad del background
self.x = 0 # Posicion que logra efecto de velocidad
def update(self):
self.x -= self.scroll_speed #se mueve la pantalla dando el efecto
if self.x <= -self.width:
self.x = 0 #Vuelve a la posicion inicial
#Dibuja la imagen dando efecto de movimiento
def draw(self, screen):
screen.blit(self.image, (self.x, 0))
screen.blit(self.image, (self.x + self.width, 0))