动画形状

时间:2014-04-10 15:59:45

标签: python animation pygame

我试图让我创建的形状在屏幕上移动。我从谷歌那里得到的一张照片在屏幕右侧移动,但现在我想要我创建的圈子移动。这是我的编码。我错过了什么,我错过了什么。我创建的圆圈在屏幕上,但不会移动

bif="background.jpg"
mif="volleyball.png"

import pygame, sys
from pygame.locals import *

pygame.init()
screen=pygame.display.set_mode((1280,800),0,32)

triangle= [[1000, 500], [950, 500], [975, 450]]
color= (250,145,123)

background=pygame.image.load(bif).convert()
ball_c=pygame.image.load(mif).convert_alpha()

x=0
y=0
clock=pygame.time.Clock() #We opened our clock method.
speed=250 #We set our speed

color=(176,23,31)
position=(2,412)
radius=(90)

movex = 0
movey = 0
while True:
    for event in pygame.event.get():
        if event.type== QUIT:
            pygame.quit()
            sys.exit()

    screen.blit(background, (0,0))
    screen.blit(ball_c, (x,160))

    milli=clock.tick()
    seconds=milli/1000. #We converted milliseconds into seconds
    dm=seconds*speed
    x+=dm 

    x+=dm
    y+=dm
    movex+=dm
    movey+=dm

    if x>1280: 
        x=0


    for point in triangle:
        point[0] += movey
        if y == 150:
            point[1]= movex

    screen.lock()
    pygame.draw.circle(screen,color,position,radius)
    pygame.draw.polygon(screen,color,triangle)

    screen.unlock()

    pygame.display.update()

1 个答案:

答案 0 :(得分:1)

每次draw circle

pygame.draw.circle(screen,color,position,radius)

你把它放在position。这是最初设定的:

position=(2,412)

但是永远不会改变,所以它总是在同一个地方。您需要每次循环更新position,例如

position = (position[0] + dx, position[1] + dy)

dxdy的位置是circle在每个轴上移动的距离。