我有一个类警报,它在pygame中创建一个弹出类型功能。我想在弹出体中绘制文本,但它不起作用。我通过渲染文本并将其保存到位图来测试它。只是一个黑盒子。杀死我的东西,下面的那个类(按钮)工作完美,并被称为类警报的实例!至少我知道它不能成为参数传递问题我猜
class alert(object):
def __init__(self,msg,x,y,dim_x,dim_y,the_game,screen,size=16):
self.x = x
self.y = y
self.e_x = x+dim_x
self.e_y = y+dim_y
self.dim_x=dim_x
self.real_dim_y=dim_y
self.dim_y = dim_y
self.the_game = the_game
self.the_screen = screen
self.font = the_game.font.Font(None,size)
self.bitmap = the_game.Surface((dim_x,dim_y))
self.bitmap.fill(ALERT_BODY)
print "msg: %r" % msg
if((msg!=None) and (msg!=False)):
text = self.font.render(msg,1,(0,0,0))
the_game.image.save(text,"text-test.bmp")
self.bitmap.blit(text,[5, (self.e_y-((3*self.dim_y)/4))])
the_game.image.save(self.bitmap,"alert-test.bmp")
newx = self.x+(self.dim_y-45)/2
newy = (self.e_y-(dim_y/6))
self.close_button = button(the_game,newx,newy,45,12,ALERT_BUTTON,"OK",18)
ret = self.close_button.setaction(self.btn_quit,False)
self.Answer = False
self.Quit=False
由于某种原因,这是有效的,我看不出差异:
class button(object):
def __init__(self,pygame,x,y,dim_x,dim_y,color,phrase,font_size,text_color=(255,255,255)):
self.is_clicked = False
self.has_next = False
self.next = None
self.has_prev = False
self.prev = None
self.enable=True
self.x=x
self.y=y
self.dim_x=dim_x
self.dim_y=dim_y
self.e_x=x+dim_x
self.e_y=y+dim_y
self.color=color
self.color2=color
self.phrase=phrase
self.has_action=False
self.regularbitmap = pygame.Surface((dim_x,dim_y))
self.clickedbitmap = pygame.Surface((dim_x,dim_y))
self.regularbitmap.fill(color)
self.clickedbitmap.fill((255,255,255))
font = pygame.font.Font(None,font_size)
text1 = font.render(phrase,1,text_color)
text2 = font.render(phrase,1,(240,240,32))
self.regularbitmap.blit(text1,[1, 1])
self.clickedbitmap.blit(text2,[1, 1])
self.currentbitmap = self.regularbitmap