鱼C论坛

 找回密码
 立即注册
查看: 1799|回复: 5

[已解决]求助pygame

[复制链接]
发表于 2022-7-1 09:38:44 | 显示全部楼层 |阅读模式

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

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

x
照着小甲鱼的那个跑图片的程序敲的为啥运行后是黑屏啊
import pygame as pg
import sys

pg.init()

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

screen = pg.display.set_mode(size)
pg.display.set_caption('hellow world')

sxc = pg.image.load('sxc.jpg')
position = sxc.get_rect()

while True:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            sys.exit()
            
    position = position.move(speed)

    if position.left < 0 or position.right > width:
        sxc = pg.transform.flip(sxc, True, False)
        speed[0] = -speed[0]

    if position.top < 0 or position.bottom > height:
        speed[1] = -speed[1]

screen.fill(bg)
screen.blit(sxc, position)
pg.display.flip()
pygame.time.delay(10)
最佳答案
2022-7-1 18:15:44
import pygame as pg
import sys

pg.init()

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

screen = pg.display.set_mode(size)
pg.display.set_caption('hellow world')

sxc = pg.image.load('D:\\turtle.png')
position = sxc.get_rect()

while True:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            sys.exit()
            
    position = position.move(speed)

    if position.left < 0 or position.right > width:
        sxc = pg.transform.flip(sxc, True, False)
        speed[0] = -speed[0]

    if position.top < 0 or position.bottom > height:
        speed[1] = -speed[1]

    # 这里要将下列代码缩进到while循环下,否则下列代码将不会执行
    screen.fill(bg)
    screen.blit(sxc, position)
    pg.display.flip()
    pg.time.delay(10)  # 这里没有pygame,要将pygame改为pg
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-7-1 10:39:25 | 显示全部楼层


255,255,255 就是黑色

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-7-1 11:47:12 | 显示全部楼层
Twilight6 发表于 2022-7-1 10:39
255,255,255 就是黑色

可是改这个数后还是这样
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-7-1 11:47:52 | 显示全部楼层
d:\1.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-7-1 11:48:22 | 显示全部楼层
d:/1.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-7-1 18:15:44 | 显示全部楼层    本楼为最佳答案   
import pygame as pg
import sys

pg.init()

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

screen = pg.display.set_mode(size)
pg.display.set_caption('hellow world')

sxc = pg.image.load('D:\\turtle.png')
position = sxc.get_rect()

while True:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            sys.exit()
            
    position = position.move(speed)

    if position.left < 0 or position.right > width:
        sxc = pg.transform.flip(sxc, True, False)
        speed[0] = -speed[0]

    if position.top < 0 or position.bottom > height:
        speed[1] = -speed[1]

    # 这里要将下列代码缩进到while循环下,否则下列代码将不会执行
    screen.fill(bg)
    screen.blit(sxc, position)
    pg.display.flip()
    pg.time.delay(10)  # 这里没有pygame,要将pygame改为pg
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-29 10:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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