Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopUp.py
More file actions
Latest commit
43 lines (34 loc) · 1.17 KB
/
Copy pathPopUp.py
File metadata and controls
43 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
importpygame
importtime
classPopUp(object):
def__init__(self, screen):
self._screen=screen
self.fnt=pygame.font.SysFont("MS Comic Sans", 30)
self.color= (245, 101, 44) # orange ;)
self.popUps= []
self.defaultDuration=3
defsinglePopUp(self, txt, duration=0):
ifduration==0:
duration=self.defaultDuration
self.popUps= []
self.popUps.append({"txt": txt, "start": time.time(), "duration": duration})
defaddPopUp(self, txt, duration=0):
ifduration==0:
duration=self.defaultDuration
self.popUps.append({"txt": txt, "start": time.time(), "duration": duration})
defdrawPopUps(self):
iflen(self.popUps) ==0:
returnFalse
fullText=""
foriinrange(len(self.popUps)):
iftime.time() >self.popUps[i]['start'] +self.popUps[i]['duration']:
self.popUps.pop(i)
break
for_popUpinself.popUps:
fullText+=_popUp['txt'] +" "
# TODO: multilines!
# http://stackoverflow.com/questions/2770886/pygames-message-multiple-lines
iffullText!="":
xPos= (self._screen.get_width() /2)
self._screen.blit(self.fnt.render(fullText, True, self.color), (xPos- (self.fnt.size(fullText)[0] /2), 5))
returnTrue