pythonleelee 发表于 2022-7-1 09:38:44

求助pygame

照着小甲鱼的那个跑图片的程序敲的为啥运行后是黑屏啊
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 = -speed

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

screen.fill(bg)
screen.blit(sxc, position)
pg.display.flip()
pygame.time.delay(10)

Twilight6 发表于 2022-7-1 10:39:25



255,255,255 就是黑色

pythonleelee 发表于 2022-7-1 11:47:12

Twilight6 发表于 2022-7-1 10:39
255,255,255 就是黑色

可是改这个数后还是这样

pythonleelee 发表于 2022-7-1 11:47:52

d:\1.png

pythonleelee 发表于 2022-7-1 11:48:22

d:/1.png

临时号 发表于 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 = -speed

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

    # 这里要将下列代码缩进到while循环下,否则下列代码将不会执行
    screen.fill(bg)
    screen.blit(sxc, position)
    pg.display.flip()
    pg.time.delay(10)# 这里没有pygame,要将pygame改为pg
页: [1]
查看完整版本: 求助pygame