|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 23433213@qq.com 于 2019-4-23 08:32 编辑
程序代码为课程中的示例代码,在windows系统上可以正常运行。
在mac电脑上pygame已正确安装,在运行上面的代码时会提示如下错误:
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: Interlace handling should be turned on when using png_read_image
导致图片无法显示,百度上也没有太符合的解决办法,求助大神们帮忙看看。
import pygame
import sys
# 初始化Pygame
pygame.init()
size = width, height = 600, 400
speed = [-2, 1]
bg = (255, 255, 255) # RGB
# 创建指定大小的窗口 Surface
screen = pygame.display.set_mode(size)
# 设置窗口标题
pygame.display.set_caption("初次见面,请大家多多关照!")
# 加在图片
turtle = pygame.image.load("turtle.png").convert_alpha()
# 获得图像的位置矩形
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:
# 翻转图像
turtle = pygame.transform.flip(turtle, True, False)
# 反方向移动
speed[0] = -speed[0]
if position.top < 0 or position.bottom > height:
speed[1] = -speed[1]
# 填充背景
screen.fill(bg)
# 更新图像
screen.blit(turtle, position)
# 更新界面
pygame.display.flip()
# 延迟10毫秒
pygame.time.delay(10)
|
|