import pygame import sys # 就是两个surface对象,一个surface对象在另一个surface对象上移动,然后不断刷新,形成动画, # 加个滑块,碰撞检测,以及得分和难度提升就是个小游戏了 # 初始化pygame pygame.init() #设置窗口的宽高 size = width, height = 300, 300 # 图片运行的速度 speed = [-3, 1] # 背景颜色,类似js中rgb bg = (255, 255, 255) # 创建一个surface对象作为画布,作为背景 screen = pygame.display.set_mode(size) # 设置窗口标题 pygame.display.set_caption("初次见面,请大家多多关照!") # pygame加载图片,并将图片转换为surface对象 turtle = pygame.image.load('timg.jpg') # 获得该surface对象的矩形区域(这个矩形区域也是一个对象) position = turtle.get_rect() # 进入死循环 while True: # 设置退出条件(退出程序) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() # 图像移动(move,不是废话吗) 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) # 将矩形surface对象填充到screen这个surface对象上 screen.blit(turtle, position) # 刷新图片 pygame.display.flip() # 加入是毫秒延迟,防止程序跑的太快,滑稽乱蹿 pygame.time.delay(15)
简单图片或者gif动画
猜你喜欢
转载自blog.csdn.net/qq_28070007/article/details/80332831
今日推荐
周排行