I have a class alert which creates a popup type feature in pygame. I want to draw text to the popup body, but it doesn't work. I tested it by rendering the text and saving it to a bitmap. Just a black box. The thing that kills me, that class (button) below works perfectly, and gets called as an instance of class alert! At least I know it can't be a parameter passing issue I guess
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
this works for some reason, and I don't see the difference:
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