2017-05-27 32 views
0

だから、私はパイゲームをしゃぶりつけていましたが、私はボールを持っていますが、このボールを動かすと、フェードアウトのシャドウトレイルを残したいのですが、シャドートレイルがほとんど見えない場所では速くなります。Pygameのオブジェクトの移動速度はどのようにすることができますか?

"clock.tick()"を調整するとこの問題はかなり解決されますが、その場合は特定のオブジェクトだけが必要です。この場合はボールが遅くなるだけです。私は必ずしもスピードを落とす必要はありませんが、私は退屈な影の軌跡を見えるようにするためにできることを考えました。ここでは、コードは次のとおり

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 ボールが最も暗い図であり、それは何の動きが発生しない場合、最終的に消失する(軌跡)を移動させるように、それは軽いものを残す一方。

ありがとうございます。

答えて

0

clock.tick(40)ゲームにFPS制限を設定するだけです。

明らかではありませんが、私は "バックグラウンドエフェクト"と言うと、メインループの速度がclock.tickで定義されていると言います。したがって、40を他の値に変更する代わりに、移動するオブジェクトの速度を下げるために、各移動のピクセルを単純に減らすことができます。

+0

私が話しているバックグラウンドエフェクトは、画面上で起こるアニメーション、側のラインアニメーション、それがそのままの状態で欲しいということです。私のボールの動きをどれだけ減らしても増やしても、シャドーはやや速すぎてほとんど見えません。ボールの動きが私のアニメーションとして機能するようにしたいのですが、私のボールが白と黒のグラデーションの軌跡を残すように、私の背景効果にかなり似ています。 ボールの色を変更すると、「軌跡」が少し見やすくなります。 –

+0

"ボール/シャドウ"のコードに入り、背景効果のようにスピードを定義する必要があるようです。 –

関連する問題