0

I'm making a rpg game in pygame and I don't know how to make the background change when touching edge and when I try, it won't work and it says a syntax error at line 31

import pygame
WIDTH = 480
HEIGHT = 365
player = Actor("character.png")
player.pos = WIDTH/2, HEIGHT/2
player.posx = WIDTH/2
player.posy = HEIGHT/2
tent = Actor("tent2.png")
tent.pos = WIDTH/3, HEIGHT/1.3
campfire = Actor("campfire.png")
campfire.pos = WIDTH/5, HEIGHT/1.3

def update():
    if keyboard.a and player.left > 0:
        player.left -= 3
    if keyboard.d and player.right < WIDTH:
        player.right += 3
    if keyboard.w and player.top > 0:
        player.top -= 3
    if keyboard.s and player.bottom < HEIGHT:
        player.bottom += 3

if player.pos = WIDTH/1, HEIGHT/1:
        screen.blit("bg3.png",(0,0))
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
green
  • 1
  • 1
  • This is not [PyGame](https://www.pygame.org/news), it is [Pygame Zero](https://pygame-zero.readthedocs.io/en/stable/). You have to use the [tag:pgzero] tag instead of the [tag:pygame] tag. – Rabbid76 Sep 25 '21 at 05:13

1 Answers1

0

The 1st argument of pygame.Surface.blit must be a pygame.Surface object. Use pygame.image.load to load new image from a file and to create a Surface.

Load the file once:

bg3_surf = pygame.image.load("bg3.png")

And use it later in your code:

screen.blit("bg3.png",(0,0))

screen.blit(bg3_surf, (0, 0))
Rabbid76
  • 202,892
  • 27
  • 131
  • 174