pygame 的图片为什么加载不出来?

问答 小强飞飞飞 ⋅ 于 2019-03-29 14:19:59 ⋅ 最后回复由 青牛 2019-03-29 17:56:45 ⋅ 5077 阅读

代码如下:

Unit aaa: Pygame Hello Wall Ball Game version 1

import pygame, sys

pygame.init()

size = width, height = 600, 400

speed = [1, 1]

BLACK = 0, 0, 0

screen = pygame.display.set_mode(size)

pygame.display.set_caption("Pygame壁球")

ball = pygame.image.load("PYG02-ball.gif")

ballrect = ball.get_rect()

fps = 300

fclock = pygame.time.Clock()

while True:

for event in pygame.event.get():

if event.type == pygame.QUIT:

sys.exit()

elif event.type ==pygame.KEYDOWN:

if event.key==pygame.K_LEFT:

speed[0]=speed[0] if speed[0]==0 else (abs(speed[0] - 1))* int(speed[0]/abs(speed[0]))

if event.key == pygame.K_RIGHT:

speed[0] = speed[0]+1 if speed[0]>0 else speed[0]-1

elif event.key == pygame.K_UP:

speed[1] = speed[1] + 1 if speed[1] > 0 else speed[1]-1

elif event.key == pygame.K_DOWN:

speed[1] = speed[1] + 1 if speed[1] > 0 else (abs(speed[1]) - 1)* int(speed[1]/abs(speed[1]))

ballrect = ballrect.move(speed[0], speed[1])

if ballrect.left < 0 or ballrect.right > width:

speed[0] = - speed[0]

if ballrect.top < 0 or ballrect.bottom > height:

speed[1] = - speed[1]

screen.fill(BLACK)

screen.blit(ball, ballrect)

pygame.display.update()

fclock.tick(fps)
file
file
file

成为第一个点赞的人吧 :bowtie:
回复数量: 1
  • 青牛 国内首批大数据从业者,就职于金山,担任大数据团队核心研发工程师
    2019-03-29 17:56:45

    是找不到文件吗?

暂无评论~~
  • 请注意单词拼写,以及中英文排版,参考此页
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
  • 支持表情,可用Emoji的自动补全, 在输入的时候只需要 ":" 就可以自动提示了 :metal: :point_right: 表情列表 :star: :sparkles:
  • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif,教程
  • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
Ctrl+Enter