1

描画要素をアニメーション化しようとしましたが、成功しませんでした。インポートした画像をアニメーション化できますが、pygame によって生成された描画をアニメーション化しようとすると、静的なままになります。

編集:「アニメーション化」とは、「動く」ことを意味します。円を x 方向と y 方向に移動させる場合と同様です。

これは私のコードです:

import pygame, sys
from pygame.locals import *

pygame.init()

FPS = 60
WIDTH = 600
HEIGHT = 500
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
ballx = WIDTH / 2
bally = HEIGHT / 2
ball_vel = [1, 1]
ball_pos =(ballx, bally)
RADIUS = 20

# Game Loop:
while True:
    # Check for quit event
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    # Erase the screen (I have tried with and without this step)
    DISPLAYSURF.fill(BLACK)

    # Update circle position
    ballx += ball_vel[0]
    bally += ball_vel[1]

    # Draw Circle (I have tried with and without locks/unlocks)
    DISPLAYSURF.lock()
    pygame.draw.circle(DISPLAYSURF, WHITE, ball_pos, RADIUS, 2)
    DISPLAYSURF.unlock()

    # Update the screen
    pygame.display.update()
    fpsClock.tick(FPS)

表示面をロック/ロック解除して、またはせずに試しました(ドキュメントが示唆しているように)。画面を更新する前に、画面を消去して、または消去せずに試しました(いくつかのチュートリアルが示唆しているように)。私はそれを機能させることができません。

私は何を間違っていますか?描画要素をどのようにアニメーション化しますか?

御時間ありがとうございます。

4

2 に答える 2

3

ball_pos タプルを更新していません: 開始座標に設定します:

ballx = WIDTH / 2
bally = HEIGHT / 2
ball_vel = [1, 1]
ball_pos =(ballx, bally)

後で ballx と bally を更新しますが、ball_pos を ballx と bally に再度設定することはありません。while ループで、ballx と bally を設定した後、次のようにします。

ball_pos = (ballx,bally)
于 2012-11-23T11:57:05.893 に答える
1
import pygame, sys
from pygame.locals import *

pygame.init()

FPS = 60
WIDTH = 600
HEIGHT = 500
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
ballx = WIDTH / 2
bally = HEIGHT / 2
ball_vel = [1, 1]
ball_pos =(ballx, bally)
RADIUS = 20

# Game Loop:
while True:
    # Check for quit event
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    # Erase the screen (I have tried with and without this step)
    DISPLAYSURF.fill(BLACK)

    # Update circle position
    ballx += ball_vel[0]
    bally += ball_vel[1]
    ball_pos =(ballx, bally)

    # Draw Circle (I have tried with and without locks/unlocks)
    pygame.draw.circle(DISPLAYSURF, WHITE, ball_pos, RADIUS, 2)

    # Update the screen
    pygame.display.flip()
    fpsClock.tick(FPS)

フリップ = 更新()

于 2014-07-16T21:38:02.677 に答える