[Python] How can i scale up all my sprites in pygame?

Discussão em 'Python' iniciado por Stack, Janeiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    I want to scale up the sprites i have in window surface. I'm using 16x16 sprites in 800x600 resolution and it look like this. Image

    I try to using pygame.Surface then use .blit but the result is blank window before. Here is my code.


    game.py
    ​

    from scripts.settings import *
    from scripts.level import Level

    class Game:
    def __init__(self):
    pygame.init()
    # Setup Window
    self.screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
    pygame.display.set_caption('Platformer')
    self.clock = pygame.time.Clock()
    self.running = True

    self.tmx_maps = {0: load_pygame(join('data', 'map', 'world.tmx'))}


    self.level = Level(self.tmx_maps[0])

    def run(self):
    while self.running: # Game Loop
    # Delta time for frame independencies
    dt = self.clock.tick(FPS) / 1000

    for event in pygame.event.get():
    if event.type == pygame.QUIT:
    self.running = False
    # Update

    # Draw
    self.level.run()
    pygame.display.update()

    pygame.quit()


    if __name__ == '__main__':
    game = Game()
    game.run()


    level.py
    ​

    from scripts.settings import *
    from scripts.sprites import Sprite

    class Level:
    def __init__(self, tmx_map):
    self.screen = pygame.display.get_surface()

    # Groups
    self.all_sprites = pygame.sprite.Group()


    self.setup(tmx_map)

    def setup(self, tmx_map):
    for x, y, surf in tmx_map.get_layer_by_name('Terrain').tiles():
    Sprite(surf, (x * TILE_SIZE, y * TILE_SIZE), self.all_sprites)


    def run(self):
    self.screen.fill('light blue')
    self.all_sprites.draw(self.screen)

    Continue reading...

Compartilhe esta Página