【发布时间】:2011-06-19 10:15:44
【问题描述】:
我需要为我的 rpg 创建一个 TextBox / MessageBox /StatusBox 等。我做了一个文本框 类,但它似乎不起作用。它会破坏表面,但不显示任何文本。
代码:
class TextBox(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.initFont()
self.initImage()
self.initGroup()
self.setText(['a','b'])
def initFont(self):
pygame.font.init()
self.font = pygame.font.Font(None,3)
def initImage(self):
self.image = pygame.Surface((200,80))
self.image.fill((255,255,255))
self.rect = self.image.get_rect()
self.rect.center = (0,0)
def setText(self,text):
tmp = pygame.display.get_surface()
x_pos = self.rect.left+5
y_pos = self.rect.top+5
for t in text:
x = self.font.render(t,False,(0,0,0))
tmp.blit(x,(x_pos,y_pos))
x_pos += 10
if (x_pos > self.image.get_width()-5):
x_pos = self.rect.left+5
y_pos += 10
def initGroup(self):
self.group = pygame.sprite.GroupSingle()
self.group.add(self)
【问题讨论】:
-
如果您找到自己问题的答案,您应该将其作为答案发布,以便您可以将问题标记为已回答。我认为您必须在提出问题后等待 24 小时才能执行此操作。
-
很抱歉。我打算这样做,但不得不等待 24 小时,所以我进行了编辑。现在完成了。
-
酷。你也可以勾选你自己的问题。 ;)
-
哈哈!我做到了!没有任何痛苦就获得了额外的声誉! :D
-
:D 好吧,不要认为它是“作弊”。它是这样设计的。即使您没有帮助其他人,您仍然在问答数据库中添加了一个带有有效解决方案的新条目,因此您应该得到一点声誉。