2014-01-29 1 views
1

저는 PyGame을 사용하여 드래곤 커브가 펼쳐지는 것을 시뮬레이션하고 있습니다. 나는 이미 서로를 회전하면서 모든 점을 추적하는 성공적인 버전을 만들었지 만 분명히 몇 번의 반복을 거친 후에는 상당히 느려지 기 시작합니다. 이를 가속화하기 위해, 그려진 세그먼트를 이미지 변수에 저장하고 화면의 세그먼트를 변수에 저장하고 많은 점을 추적하는 대신 움직이는 그림을 그립니다. 다음 중 하나를 어떻게 할 수 있습니까? 다음 올바른 위치 PyGame의 오프 스크린 디스플레이로 그리는 방법

  • 저장
  • 나는 몇 가지를 읽고 시도 변수 이미지에 보이는 디스플레이의 섹션에있는 화면으로 그려됩니다 오프 스크린 이미지 변수에

    • 그리기 PyGame 문서의 일부이지만, 나는 어떤 성공도 가져 오지 않았다.

      감사합니다.

    답변

    2

    추가 곡면 개체를 만들고 그 위에 그림을 그리는 것이 해결책입니다. 이 표면 객체는 다음과 같이 디스플레이 표면 객체에 그릴 수 있습니다.

    파이 게임 표면 개체

    추가 정보를 찾을 수 here

    import pygame, sys 
    
    SCREEN_SIZE = (600, 400) 
    BG_COLOR = (0, 0, 0) 
    LINE_COLOR = (0, 255, 0) 
    pygame.init() 
    clock = pygame.time.Clock() # to keep the framerate down 
    
    image1 = pygame.Surface((50, 50)) 
    image2 = pygame.Surface((50, 50)) 
    image1.set_colorkey((0, 0, 0)) # The default background color is black 
    image2.set_colorkey((0, 0, 0)) # and I want drawings with transparency 
    
    screen = pygame.display.set_mode(SCREEN_SIZE, 0, 32) 
    screen.fill(BG_COLOR) 
    
    # Draw to two different images off-screen 
    pygame.draw.line(image1, LINE_COLOR, (0, 0), (49, 49)) 
    pygame.draw.line(image2, LINE_COLOR, (49, 0), (0, 49)) 
    
    # Optimize the images after they're drawn 
    image1.convert() 
    image2.convert() 
    
    # Get the area in the middle of the visible screen where our images would fit 
    draw_area = image1.get_rect().move(SCREEN_SIZE[0]/2 - 25, 
                SCREEN_SIZE[1]/2 - 25) 
    
    # Draw our two off-screen images to the visible screen 
    screen.blit(image1, draw_area) 
    screen.blit(image2, draw_area) 
    
    # Display changes to the visible screen 
    pygame.display.flip() 
    
    # Keep the window from closing as soon as it's finished drawing 
    # Close the window gracefully upon hitting the close button 
    while True: 
        for event in pygame.event.get(): 
         if event.type == pygame.QUIT: 
          pygame.quit() 
          sys.exit(0) 
        clock.tick(30) 
    
    관련 문제