鱼C论坛

 找回密码
 立即注册
查看: 1110|回复: 4

有关pygame记载图片问题

[复制链接]
发表于 2019-2-16 13:27:29 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
我学习pygame制作飞机大战的游戏老是加载不了而且打不开图片是为什么,给了路径也不行,快没信心了,求助。
基本格式也没错呀!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-2-16 16:02:27 | 显示全部楼层
详情,错误截图?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-2-19 21:17:41 | 显示全部楼层
import pygame
import sys

#初始化
pygame.init()

size=width,height = 600,400
speed = [-2,1]
bg = (255,255,255)

#创建指定大小的窗口
screen = pygame.display.set_mode(size)
#设置窗口标题
pygame.display.set_caption("我的第一个游戏")

#加载图片
turtle = pygame.image.load("turtle.png")
#获得图像的位置矩形
position = turtle.get_rect()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
            
    #移动图像
    position = position.move(speed)

    if position.left < 0 or position.right > width:
        #翻转图像
        trutle = pygame.transform.flip(trutle,True,False)
        #反方向移动
        speed[0] = -speed[0]


    if position.top < 0 or positon.bottom > height:
       speed[1] = -speed[1]
      
    #填充背景
    screen.fill(bg)
    #更新图片
    screen.blit(turtle,position)
    #更新界面
    pygamwe.display.flip()
    #延迟10秒
    pygame.time.delay(10)



结果:Traceback (most recent call last):
  File "C:/Users/Administrator/Desktop/turtle.py", line 17, in <module>
    turtle = pygame.image.load("turtle.png")
pygame.error: Couldn't open turtle.png
      
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-3-2 15:53:10 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-3-2 15:53:41 | 显示全部楼层
为什么没回复?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-13 23:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表