|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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)
- 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
复制代码
|
|