本文為大家分享了pygame游戲之旅的第3篇,供大家參考,具體內(nèi)容如下
載入car圖片(我自己畫的),需要用到pygame.image模塊,定義carImg用于接收載入的圖片
carImg = pygame.image.load('car.png')
定義一個(gè)car函數(shù)綁定car的位置
def car(x, y): gameDisplay.blit(carImg,(x,y))
為窗口填充白色并調(diào)用car函數(shù),更新窗口
gameDisplay.fill(white)car(x,y)pygame.display.update()
完整代碼是:
import pygame pygame.init() white = (255,255,255) display_width = 800display_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.45y = 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()
結(jié)果圖:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林站長站。
新聞熱點(diǎn)
疑難解答
圖片精選