So, how tedious would it be to put down each individual pixel for a game? That's what pictures are for! First up, I'll show you how to insert an image. First you need to save the following image as Ball.png, and put it in...wherever you keep your Python programs. For me, it's Python 32, and if your computer is anything like mine, your programs folder will be in your Computer section, in Local Disk (C:). Now, here's that picture:
Remember, Ball.png. Once it's all good and saved, type in this as a new program:
import pygame, sys
pygame.init()
screen=pygame.display.set_mode([640, 480])
screen.fill([255, 255, 255])
ball = pygame.image.load("Ball.png")
screen.blit(ball, [50, 50])
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
When you run the program, it should display a big red dot around the top-left corner.
Wow. A red dot. That's so amazing. But, hey! We're one step closer to being talented programmers!
We'll continue all this picture stuff next time. Bye!
No comments:
Post a Comment