- 论坛徽章:
- 0
|
在窗口显示一个会动的bmp图片,运行程序需要准备一个sample1.bmp文件,当是入门程序好啦。
import sys, pygame
pygame.init()
size = width, height = 320, 240
speed = [2, 2]
black = 0, 0, 0
screen = pygame.display.set_mode(size)
ball = pygame.image.load("sample1.bmp")
ballrect = ball.get_rect()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
ballrect = ballrect.move(speed)
if ballrect.left width:
speed[0] = -speed[0]
if ballrect.top height:
speed[1] = -speed[1]
screen.fill(black)
screen.blit(ball, ballrect)
pygame.display.flip()
# import time
# time.sleep(0.01)
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4565/showart_54758.html |
|