所以我在玩pygame,问题是我有一个球,而当我移动这个球的时候,我希望它离开逐渐消失的影子轨迹,但问题是它发生在“影子轨迹”几乎看不见的地方。在
调整“时钟滴答声()“很好地解决了这个问题,但我只想要那个特定的物体,在这种情况下,球是唯一减速的物体。我不需要降低速度,但我想这是我可以做的事情,使我的褪色阴影痕迹可见。代码如下:import pygame
pygame.init()
game_over = False
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
screen_size = (500, 500)
ball_x, ball_y = 261.5, 261.5
post_xa, post_ya, post_xb, post_yb = 261.5, 261.5, 261.5, 261.5
line = []
ival = 0
clock = pygame.time.Clock()
screen = pygame.display.set_mode(screen_size)
pygame.display.set_caption("Keeping it Small and Simple")
for x, y in zip(range(250, -1, -5), range(0, 250, 5)):
line.append([y, 0, 0, x])
for x, y in zip(range(0, 250, 5), range(250, 500, 5)):
line.append([500, x, y, 0])
for x, y in zip(range(500, 250, -5), range(250, 500, 5)):
line.append([500, y, x, 500])
for x, y in zip(range(250, -1, -5), range(500, 250, -5)):
line.append([0, y, x, 500])
while not game_over:
screen.fill(BLACK)
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
pressed = pygame.key.get_pressed()
if pressed[pygame.K_UP]:
ball_y -= 8
post_ya -= 8
if pressed[pygame.K_DOWN]:
ball_y += 8
post_ya += 8
if pressed[pygame.K_LEFT]:
ball_x -= 8
post_xa -= 8
if pressed[pygame.K_RIGHT]:
ball_x += 8
post_xa += 8
#Code for the shadow
colorb = 0
for i in range(8):
colors = colorb, colorb, colorb
pygame.draw.circle(screen, (colors), (int(post_xb), int(post_yb)), int(21.5))
colorb += 30
if post_xa > post_xb:
post_xb += 1
if post_xa < post_xb:
post_xb -= 1
if post_ya > post_yb:
post_yb += 1
if post_ya < post_yb:
post_yb -= 1
pygame.draw.circle(screen, WHITE, (int(ball_x), int(ball_y)), int(21.5))
# background effect
col = 0
cur = ival
for i in range (40):
x1, y1, x2, y2 = line[cur]
pygame.draw.line(screen, (col,col,col), (x1, y1), (x2, y2), 2)
cur += 1
if cur >= len(line):
cur = 0
col += 240 / 40
ival += 1
if ival >= len(line):
ival = 0
pygame.display.flip()
clock.tick(40)
pygame.quit()
下面是一个粗略的例子:
https://i.ytimg.com/vi/DzTyqcXhitY/maxresdefault.jpg
而球是最暗的,当它移动(轨迹)时,它会留下较亮的图形,如果没有移动,这些图形最终会消失。在
提前谢谢你。在