2012-09-22 7 views
2

그래서 나는 이미지로 화살표가 있습니다. 그것의 외형에 의해, 그것은 중심을 우회전하고있는 것처럼 보인다. 그러나 어느 방향 으로든 회전 할 때 각면에서 약 75도 각도로 오차가있을 때 ValueError : 서페이스 사각형 밖에 서페이스 표면이 뒤덮는 서페이스 사각형파이 게임에서 이미지 회전

문제가 무엇인지 잘 모르겠습니다. pygames 웹 사이트의 회전 기능 해제. 문제가 무엇인지 아는 사람이라면 도움을 주시면 감사하겠습니다. 해당 페이지에

screen = pygame.display.set_mode(ss) 
arrow = pygame.image.load("obj.png").convert_alpha() 

x = 400 
y= 300 
a = 0 
turn = 2 

def rot_center(image, angle): 
    """rotate an image while keeping its center and size""" 
    orig_rect = image.get_rect() 
    rot_image = pygame.transform.rotate(image, angle) 
    rot_rect = orig_rect.copy() 
    rot_rect.center = rot_image.get_rect().center 
    rot_image = rot_image.subsurface(rot_rect).copy() 
    return rot_image 

while True: 
    screen.fill((255, 255, 255)) 
    if turn == 1: 
     a += 10 
    if turn == 2: 
     a -=10 
    if a == 90: 
     turn = 2 
    if a == -90: 
     turn = 1 

    rotarrow = rot_center(arrow, a) 
    screen.blit(rotarrow, (x, y)) 
    pygame.display.update() 
    sleep(0.1) 

답변

4

첫 번째 함수 정사각형 이미지 만 제공됩니다 : 여기에 코드입니다. 임의의 치수

는 두 번째 사용

def rot_center(image, rect, angle): 
     """rotate an image while keeping its center""" 
     rot_image = pygame.transform.rotate(image, angle) 
     rot_rect = rot_image.get_rect(center=rect.center) 
     return rot_image,rot_rect 
관련 문제