求助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)
255,255,255 就是黑色
Twilight6 发表于 2022-7-1 10:39
255,255,255 就是黑色
可是改这个数后还是这样 d:\1.png d:/1.png 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]