你如何让球像 sin() 图那样以重复的波浪模式移动?
问问题
3203 次
1 回答
5
您可以使用计数器、pygame'sClock
或仅pygame.time.get_ticks
计算时间。这里有一些示例代码可以帮助您入门。
import math
import pygame
pygame.init()
screen = pygame.display.set_mode((400,400))
while True:
t = pygame.time.get_ticks() / 2 % 400 # scale and loop time
x = t
y = math.sin(t/50.0) * 100 + 200 # scale sine wave
y = int(y) # needs to be int
screen.fill((0,0,0))
pygame.draw.circle(screen, (255,255,255), (x, y), 40)
pygame.display.flip()
于 2013-02-02T19:30:30.793 回答