2013-08-27 2 views
0

그래서 "z"키를 누를 때마다 텍스트 팝업이 나타나 잠시 동안 계속 blitted되도록 "씬"클래스에서 기능을 만들려고합니다.파이 게임 - 키를 누른 후에도 텍스트 블리핑

pygame.key.get_pressed()를 사용하면 Z를 누르고있는 동안 만 블리치가 발생합니다. Z가 눌 렸을 때 팝업되어 잠시 동안 화면에 계속 머물러 있기를 원합니다.

##This is inside the "scene" class## 

def printText(self, surface): 
    if self.counter < 20: 
     text = pygame.font.SysFont("Pixelated Regular", 30) 
     label = text.render("Hello", 0, (0,0,0,)) 
     surface.blit(label, (100,100)) 
     self.counter += 1 


##This is inside the main## 
if key[pygame.K_z]: 
     robsHouse.printText(screen) 

이런 경우에 나는 분명히 전에 만들 didnt는 : 나는 기본적으로 내가 "Z"의 가자 후에도 프레임의 몇 소총탄 할 수있는 텍스트합니다.

미리 감사드립니다. 당신은 텍스트가 사라 self.pressed을 설정하려는 경우 다음에 다음

self.pressed = False 

if key[pygame.K_z]: 
    self.pressed = True 

if self.pressed: 
    robsHouse.printText(screen) 

: 내가 무엇을 할 것이라고

+0

귀하의 질문은 무엇입니까? – bansi

답변

1

여기

은 예입니다 버튼을 누른 처리 여부를 정의하는 부울을 만들거나하지 않습니다 False과는 같이

을 소총탄되고 중지됩니다

def printText(self, surface): 
    if self.counter < 20: 
     text = pygame.font.SysFont("Pixelated Regular", 30) 
     label = text.render("Hello", 0, (0,0,0,)) 
     surface.blit(label, (100,100)) 
     self.counter += 1 
    else: 
     self.pressed = False 

그런 식으로 카운터가 종료되면 텍스트가 사라집니다.

희망이 있습니다.

+0

텍스트가 변경되지 않으므로 한 번 렌더링하고 캐시 된 표면을 blit 할 수 있습니다. 이 작업을 자동으로 수행하는 클래스가 필요하면 다음을 참조하십시오. http://stackoverflow.com/a/15516132/341744 – ninMonkey

+0

그래, 렌더링을 루프 밖으로 가져와 여러 번 렌더링하지 말고 루프에서 블리 팅을 유지하십시오. – Serial