Python 有人知道为什么精灵不是';我的pygames程序中的t渲染?
目前,代码在运行时没有给出任何错误。即使我只是尝试在0,0处渲染一个带有blit的管道,也不会弹出任何内容 我已经把地板和鸟都做好了,其他一切都很好。只有管道不会渲染 我一直在关注一个在线视频,甚至试图完全复制代码,它只是因为某种原因而拒绝工作Python 有人知道为什么精灵不是';我的pygames程序中的t渲染?,python,python-3.x,pygame,Python,Python 3.x,Pygame,目前,代码在运行时没有给出任何错误。即使我只是尝试在0,0处渲染一个带有blit的管道,也不会弹出任何内容 我已经把地板和鸟都做好了,其他一切都很好。只有管道不会渲染 我一直在关注一个在线视频,甚至试图完全复制代码,它只是因为某种原因而拒绝工作 import pygame import sys #defining screen size and clock variable pygame.init() screen = pygame.display.set_mode((576,1024)) c
import pygame
import sys
#defining screen size and clock variable
pygame.init()
screen = pygame.display.set_mode((576,1024))
clock = pygame.time.Clock()
#bird physics
gravity = 0.25
bird_movement = 0
#importing all of the images, and doubling their size
bg_surface = pygame.image.load("Py games/assets/background-day.png").convert()
bg_surface = pygame.transform.scale2x(bg_surface)
floor_surface = pygame.image.load("Py games/assets/base.png").convert()
floor_surface = pygame.transform.scale2x(floor_surface)
pipe_surface = pygame.image.load("Py games/assets/pipe-green.png").convert()
pipe_surface = pygame.transform.scale2x(pipe_surface)
#making all clones of pipes have rectangles
pipe_list = []
#How often pipes are made
SPAWNPIPE = pygame.USEREVENT
pygame.time.set_timer(SPAWNPIPE,1200)
bird_surface = pygame.image.load("Py games/assets/bluebird-midflap.png").convert()
bird_surface = pygame.transform.scale2x(bird_surface)
#creating the rectangle around the bird
bird_rect = bird_surface.get_rect(center = (100,512))
#Used to animate floor
floor_x_pos = 0
def draw_floor():
screen.blit(floor_surface,(floor_x_pos,900))
screen.blit(floor_surface,(floor_x_pos + 576,900))
#cloning of pipe
def create_pipe():
new_pipe = pipe_surface.get_rect(midtop = (288,512))
return new_pipe
def move_pipes(pipes):
for pipe in pipes:
pipe.centerx -= 5
return pipes
def draw_pipes(pipes):
for pipe in pipes:
screen.blit(pipe_surface,pipe)
#main game loop, renders every frame of the game
while True:
#Event Loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#checks for keypresses
if event.type == pygame.KEYDOWN:
#checks if space is pressed
if event.key == pygame.K_SPACE:
bird_movement = 0
bird_movement -= 12
if event.type == SPAWNPIPE:
pipe_list.append(create_pipe())
screen.blit(pipe_surface,(0,0))
#pipes
pipe_list = move_pipes(pipe_list)
draw_pipes(pipe_list)
#rendering the background
screen.blit(bg_surface,(0,0))
#rendering the bird and a rectangle around that detects colisions
screen.blit(bird_surface,bird_rect)
#gravity
bird_movement += gravity
bird_rect.centery += bird_movement
#more floor animation
floor_x_pos -= 1
draw_floor()
if floor_x_pos <= -576:
floor_x_pos = 0
#Causes display update and defines framerate
pygame.display.update()
clock.tick(120)
导入pygame
导入系统
#定义屏幕大小和时钟变量
pygame.init()
screen=pygame.display.set_模式((5761024))
clock=pygame.time.clock()
#鸟类物理学
重力=0.25
鸟类运动=0
#导入所有图像,并将其大小加倍
bg_surface=pygame.image.load(“Py games/assets/background day.png”).convert()
bg_surface=pygame.transform.scale2x(bg_surface)
floor_surface=pygame.image.load(“Py games/assets/base.png”).convert()
floor_surface=pygame.transform.scale2x(floor_surface)
pipe_surface=pygame.image.load(“Py games/assets/pipe green.png”).convert()
管道曲面=pygame.transform.scale2x(管道曲面)
#使所有管道克隆都具有矩形
管道列表=[]
#管道多久制造一次
SPAWNPIPE=pygame.USEREVENT
pygame.time.set_定时器(产卵管,1200)
bird_surface=pygame.image.load(“Py games/assets/bluebird midflap.png”).convert()
bird_surface=pygame.transform.scale2x(bird_surface)
#围绕鸟创建矩形
bird_rect=bird_曲面。get_rect(中心=(100512))
#用于设置地板动画
楼层x位置=0
def draw_floor():
屏蔽板(地板表面,(地板x位置,900))
屏蔽板(地板表面,(地板x位置+576900))
#管道的克隆
def create_pipe():
新建管道=管道曲面。获取矩形(中间层=(288512))
返回新管道
def移动_管道(管道):
对于管道中的管道:
管道中心X-=5
回流管
def牵引管(管道):
对于管道中的管道:
筛网(管道表面、管道)
#主游戏循环,渲染游戏的每一帧
尽管如此:
#事件循环
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
pygame.quit()
sys.exit()
#检查按键
如果event.type==pygame.KEYDOWN:
#检查是否按了空格键
如果event.key==pygame.K_空间:
鸟类运动=0
鸟类运动-=12
如果event.type==SPAWNPIPE:
管道列表。追加(创建管道())
筛网布利特(管道表面,(0,0))
#管道
管道列表=移动管道(管道列表)
绘制管道(管道列表)
#渲染背景
筛网布利特(bg_表面,(0,0))
#渲染鸟和周围用于检测合并的矩形
屏幕。blit(鸟形表面、鸟形直线)
#重力
鸟类运动+=重力
鸟_-rect.centery+=鸟_运动
#更多楼层动画
楼层x位置-=1
绘图楼()
如果地板位置背景覆盖管道。您需要在绘制背景后绘制管道:
为True时:
# [...]
#管道
管道列表=移动管道(管道列表)
#绘制管道(管道列表)问题是否已解决?