[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Drawing directly or loading images



Kai Weber wrote:
for educational purposes (learning programming with pygame) I want to
write my own version of PONG. I like to have an old style Pong version
as I remember playing in my youth on TV screen.

Can I use the drawing functions to have sprites for the bats and the
ball or should I better use images for this purpose? If I draw the balls
and bats I imagine I could scale those objects to match the screen
resolution.
Classical Pong was of course all solid rectangles. This is a prime case for drawing directly to the screen. I would recommend the Surface.fill() method.

I would recommend creating offscreen Surfaces to represent the ball and bats. Then drawing these on the screen with the traditional Surface.blit() calls. This way if you later want to replace the graphics with image files, it will require almost no change to your game code.

To create these surfaces you would use functions like this.

def get_bat_image():
size = 25, 200
color = 255, 255, 255
bat = pygame.Surface(size)
bat.fill(color)
return bat

def get_ball_image():
size = 25, 25
color = 255, 255, 255
ball = pygame.Surface(size)
ball.fill(color)
return ball

Later on you can easily change the colors, sizes, or even load an image.