2017-12-26 2 views
1

기본적으로 저는 만화책 뷰어를 디자인하는 프로젝트에서 파이 게임을 사용하고 있습니다. 이미지를로드하고 표시하고 크기를 수정했지만 크기를 조정할 때 이미지를 창에 맞출 수 없었습니다.파이 게임에서 "화면에 맞게"이미지 만들기?

지금까지 캔버스를 가로 질러 이미지가 늘어났습니다. 크기를 조정하면 위치가 그대로 유지되고 모든 것이 "이상하게 보입니다". https://github.com/averyre/ComicSnake/blob/master/comicsnake.py

특히,이 블록 :

## The GUI loop. 
while 1: 
    screenWidth, screenHeight = screen.get_size(); 
    pygame.event.wait() 
    screen.fill(black) 
    page = pygame.transform.scale(page,[screenWidth, screenHeight]); 
    screen.blit(page, pagerect) 
    pygame.display.flip() 

이 어떤 도움을 크게 감상 할 수있다 여기에 내 소스입니다!

답변

1

screen은 시작시 생성되며 크기를 변경하지 않으며 크기를 조정하는 창이 아닙니다. 당신은 창 크기를 조정하면 다음이

이 필드를 event.size, event.w, event.h을 가지고 이벤트 VIDEORESIZE 보내고 그것은 크기 조정 후 윈도우의 크기입니다.

참조 문서 : WindowResizing : pygame.org의 위키에서 event

예제 코드.
VIDEORESIZE을 사용하여 screen의 이미지 크기를 조정하는 방법을 보여줍니다.

import pygame 
from pygame.locals import * 

pygame.init() 

screen = pygame.display.set_mode((500,500), HWSURFACE|DOUBLEBUF|RESIZABLE) 
pic = pygame.image.load("example.png") #You need an example picture in the same folder as this file! 
screen.blit(pygame.transform.scale(pic, (500,500)), (0,0)) 
pygame.display.flip() 

while True: 
    pygame.event.pump() 
    event = pygame.event.wait() 
    if event.type == QUIT: 
     pygame.display.quit() 
    elif event.type == VIDEORESIZE: 
     screen = pygame.display.set_mode(event.dict['size'], HWSURFACE|DOUBLEBUF|RESIZABLE) 
     screen.blit(pygame.transform.scale(pic, event.dict['size']), (0,0)) 
     pygame.display.flip() 
+0

죄송하지만이 코드를 내 코드에 통합하는 데 문제가 있습니다. "종료"이벤트 유형 및 작동 방식을 이해하지만 창을 기준으로 크기를 조정할 수는 없습니다. 비슷한 것을 재창조하려는 시도가 있었고 동일한 문제가 있습니다. – AveryRe

+0

'QUIT' 이벤트는 중요하지 않습니다 - 당신은'VIDEORESIZE'를 사용하여 창 크기를 얻고'screen'을 재 작성하고 이미지 크기를 재조정해야합니다. 'while True'에서 모든 코드를'while' 루프에 다른 변수로 복사 할 수 있습니다. – furas

관련 문제