Python Forum
[PyGame] Changing from blocks to pictures
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Changing from blocks to pictures
#2
The basic format would be along the lines of such a class as the following. As yuu have it now you are just drawing a rect. Load an image and blit it to the players location at its assigned rect. Download this repo and playtest for examples. Check out the moving platforms one for side scroller platforms example.

class Player:
    def __init__(self, screen_rect):
        self.image = pygame.image.load('image.png').convert()
        self.rect = self.image.get_rect(center=screen_rect.center)
          
    def get_event(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                self.rect.x -= self.speed
            elif event.key == pygame.K_RIGHT:
                self.rect.x += self.speed
           
    def draw(self, surf):
        surf.blit(self.image, self.rect)
Recommended Tutorials:
Reply


Messages In This Thread
Changing from blocks to pictures - by BanditEagle - Jan-11-2020, 11:25 AM
RE: Changing from blocks to pictures - by metulburr - Jan-12-2020, 11:17 PM
RE: Changing from blocks to pictures - by metulburr - Feb-02-2020, 02:52 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020