|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
# p16_/turtle.py
import pygame
import sys
pygame.init() # 初始化pygame
size = width,height = 600,400
speed = [-2,1]
bg = (255,255,255)
screen = pygame.display.set_mode(size) #创建指定大小的窗口
pygame.display.set_caption("初次见面,请大家多多关照!") # 设置窗口标题
turtle = pygame.image.load("turtle.png")
position = turtle.get_rect() # 获得图像的位置矩形
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
position = position.move(speed) #移动图像
if position.left < 0 or position.right > width:
turtle = pygame.transform.flip(turtle,True,False) #翻转图像
speed[0] = -speed[0] #反方向移动
if position.top < 0 or position.bottom > height:
speed[1] = -speed[1]
screen.fill(bg) #填充背景
screen.blit(turtle,position) #更新图像
pygame.display.flip() #更新界面
pygame.time.delay(10) #延迟10毫秒
运行后打开了窗口但是是黑屏的,没有图像,哪里错了吗??
|
|