pygame游戏之旅 载入小车图片、更新窗口 本文为大家分享了pygame游戏之旅的第3篇,供大家参考,具体内容如下 载入car图片(我自己画的),需要用到pygame.image模块,定义carImg用于接收载入的图片 carImg = pygame.image.load('car.png') 定义一个car函数绑定car的位置 def car(x, y): gameDisplay.blit(carImg,(x,y)) 为窗口填充白色并调用car函数,更新窗口 gameDisplay.fill(white) car(x,y) pygame.display.update() 完整代码是: import pygame pygame.init() white = (255,255,255) display_width = 800 display_height = 600 gameDisplay = pygame.display.set_mode( (display_width,display_height) ) pygame.display.set_caption('A bit Racey') clock = pygame.time.Clock() carImg = pygame.image.load('car.png') def car(x, y): gameDisplay.blit(carImg,(x,y)) x = display_width * 0.45 y = display_height * 0.8 crashed = False while not crashed: for event in pygame.event.get(): if event.type == pygame.QUIT: crashed = True print(event) gameDisplay.fill(white) car(x,y) pygame.display.update() clock.tick(60) pygame.quit() quit() 结果图: 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持中文源码网。