현재 조직을 XML 문서로 내보내는 Python의 스프라이트 시트 도구에서 작업하고 있지만 미리보기에 애니메이션을 적용하는 데 문제가 있습니다. 나는 파이썬으로 프레임 속도를 측정하는 방법을 잘 모르겠습니다. 예를 들어 내가 적절한 프레임 데이터와 드로잉 기능을 모두 가지고 있다고 가정하면 초당 30 프레임 (또는 다른 임의의 속도)으로 표시하기 위해 타이밍을 코딩하는 방법은 무엇입니까?Python Animation Timing
4
A
답변
8
그것을 할 수있는 가장 쉬운 방법은 Pygame 함께 :
import pygame
pygame.init()
clock = pygame.time.Clock()
# or whatever loop you're using for the animation
while True:
# draw animation
# pause so that the animation runs at 30 fps
clock.tick(30)
그것을 할 수있는 두 번째 가장 쉬운 방법은 수동이다 :
import time
FPS = 30
last_time = time.time()
# whatever the loop is...
while True:
# draw animation
# pause so that the animation runs at 30 fps
new_time = time.time()
# see how many milliseconds we have to sleep for
# then divide by 1000.0 since time.sleep() uses seconds
sleep_time = ((1000.0/FPS) - (new_time - last_time))/1000.0
if sleep_time > 0:
time.sleep(sleep_time)
last_time = new_time
0
는 threading
모듈의 Timer
클래스가있다. 일부 목적으로 time.sleep
을 사용하는 것보다 편리 할 수 있습니다.
>>> from threading import Timer
>>> def hello(who):
... print 'hello %s' % who
...
>>> t = Timer(5.0, hello, args=('world',))
>>> t.start() # and five seconds later...
hello world
0
select? 일반적으로 I/O 완료를 대기 위해 사용하지만, 서명을 살펴 것 :
timeout = 30.0
while true:
if select.select([], [], [], timeout):
#timout reached
# maybe you should recalculate your timeout ?
관련 문제
- 1. CakePHP afterSave Timing
- 2. n900 - maemo - timing
- 3. C# High accuracy Timing
- 4. C# sub millisecond timing
- 5. UIView animation 대 CALayers
- 6. UIView animation VS core animation
- 7. jQuery animation
- 8. UIActivityIndicatorView animation
- 9. UIImage animation
- 10. element animation
- 11. UIView animation
- 12. uibutton animation
- 13. UIImageView animation
- 14. jquery animation
- 15. Timing a method and threads in .NET
- 16. jQuery Tab Fade Animation
- 17. iPhone UIImageView animation woes
- 18. iphone iads animation
- 19. jquery animation help
- 20. HTML5/CSS3 animation
- 21. UISegmentControl 및 UITableViewController animation
- 22. Objective-C UIViewImage animation
- 23. animation with jquery
- 24. Silverlight, DeepZoom zooming animation
- 25. Jquery animation 문제
- 26. Core Animation 'flip'animation
- 27. javascript canvas animation
- 28. "animation"이없는 객체 회전
- 29. jquery animation tray
- 30. zoomToRect : animation 완료시 알림
이 매우 도움이, 감사 :
그래서, 당신이 뭔가를 할 수 있습니다. 저는 Python을 처음 사용하지만 더 익숙해지기 위해 열심히 노력하고 있습니다. – eriknelson