Skip to content Skip to sidebar Skip to footer

Displaying Platforms Using Strings (Pygame)

I'm having troubling getting a platform to display in areas that I have 'P' string in. I'm trying to create a level in pygame using strings instead of set coordinates for every pla

Solution 1:

Your problem is because you create Platform() with argumenst x,y

 P = Platform(x, y)

but you do nothing with this information.

You have to remeber this values in __init__

self.rect.x = x
self.rect.y = y

or shorter

self.rect = self.image.get_rect(x=x, y=y)

And you have the same problem in class Player()


BTW: better use self.rect.x, self.rect.y instead of self.x, self.y in all classes because you can use it to check collisions - player.rect.colliderect(some_element.rect) or player.rect.collidepoint(mouse_pos)

Even pygame.sprite.Group() expects that all elements have position and size in self.rect because it use self.image and self.rect to draw them.


Post a Comment for "Displaying Platforms Using Strings (Pygame)"