我在Pygame中的问题是我不明白如何在我的游戏循环中移动ip(+2.0)之后阻止Rect移动。我需要矩形在屏幕上的某个点停止。我试图通过在Rect下面放一个if语句来停止Rect;if time\u bar==pygame.rect文件(02000100,80):时间_吧台移动\u ip(0,0). 但那没用。请帮忙!!你知道吗
import pygame
pygame.init()
display_height = 900
display_width = 600
black = (0,0,0)
white = (255,255,255)
orange = (255, 153, 0)
red = (255,0,0)
gamedisplay = pygame.display.set_mode((display_height,display_width))
pygame.display.set_caption('ye boy')
clock = pygame.time.Clock()
gamedisplay.fill(white)
pygame.display.flip()
time_bar = pygame.Rect(900,200,100,80)
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def game_loop():
font = pygame.font.Font("freesansbold.ttf", 90)
clock = pygame.time.Clock()
text = ''
intro = True
while intro:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
# drawing the input box
gamedisplay.fill(white)
# time bar and its function
pygame.draw.rect(gamedisplay, red, time_bar)
time_bar.move_ip(-2,0)
pygame.display.update()
clock.tick(60)
game_loop()
pygame.quit()
quit()
您可以定义一个
speed_x
变量并将其传递给move_ip
。当x坐标小于0时,将speed_x
设置为0以停止rect。你知道吗或者(或者另外),当矩形到达该位置时,可以将其位置设置为0:
相关问题 更多 >
编程相关推荐