求正确解答
来源:3-3 飞机大战项目开始页面
Buck_messic
2020-06-06 17:42:34
import sys
import pygame
from contants import BG_MUSIC, BG_IMG, IMG_GAME_TITLE
def main():
"""游戏入口,main方法"""
#初始化
pygame.init()
width,height =480,852
#屏幕对象
screen = pygame.display.set_mode((width,height))
#设置窗口标题
pygame.display.set_caption("飞机大战")
#加载背景图片
bg = pygame.image.load(BG_IMG)
#游戏的标题
img_game_title = pygame.image.load(IMG_GAME_TITLE)
#加载背景音乐
pygame.mixer.music.load(BG_MUSIC)
pygame.mixer.music.play(-1)#无限循环播放
pygame.mixer.music.set_volume(0.2)#设置音量大小
status = 0 #0准备中,1游戏中,2游戏结束
while True:
#1 监听事件
for event in pygame.event.get():
#退出游戏
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#更新游戏的状态
if status == 0:
#游戏准备中
screen.blit()
#绘制
screen.blit(bg,bg.get_rect())
pygame.display.flip()
if __name__ == '__main__':
main()
报错:
D:\untitled\venv\Scripts\python.exe D:/untitled1/cheapter12/main.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "D:/untitled1/cheapter12/main.py", line 45, in <module>
main()
File "D:/untitled1/cheapter12/main.py", line 38, in main
screen.blit()
TypeError: function missing required argument 'source' (pos 1)
Process finished with exit code 1
1回答
时间,
2020-06-06
同学,你好。blit()中应添加相应的参数进行绘制,如下图中的代码:绘制背景及绘制标题
如果我的回答解决了您的疑惑,请采纳!祝学习愉快~~~~
相似问题