Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 different types of objects in the game.

They all have image and rect attributes.The difference is that sprites can be grouped?

like image 214
wang John Avatar asked Oct 22 '25 13:10

wang John


1 Answers

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).


In 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.

like image 73
Rabbid76 Avatar answered Oct 25 '25 03:10

Rabbid76