Skip to content Skip to sidebar Skip to footer

What Is The Difference Between Pygame Sprite And Surface?

Check the official documents as follows: Surface objects are objects that represent a rectangular 2D image. The Sprite class is intended to be used as a base class for the differen

Solution 1:

They all have image and rect attributes [...]

No this is wrong. A pygame.Surface has not rect attribute. pygame.Surface.get_rect.get_rect() returns a rectangle with the size of the Surface object, that always starts at (0, 0) since a Surface object has no position. The rectangle returned is just a rectangle the size of the surface area starting at (0, 0).


I short words: A pygame.Surface has no location, it's just a bitmap. A pygame.sprite.Sprite is a object that consists of a Surface object and pygame.Rect object. An instance of a Sprite describes the position of an image in the game window.

Post a Comment for "What Is The Difference Between Pygame Sprite And Surface?"