0

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
jason dancks
  • 1,122
  • 3
  • 9
  • 28
  • Just a guess: You're passing `pygame` as a parameter in the function. I don't know what that's doing, but I suspect it's not the same `pygame` that you need for the line `font = pygame.font.Font(None,font_size)`. Do you get an error message? – elParaguayo Apr 07 '14 at 08:30
  • Pygame is the actual name of the class I'm trying to pass. It's possible that the object is global so simply calling it by name everywhere is good enough. I did that to get a reference to the object so I didn't have to create another one if scoping is an issue. No I don't get any errors running the code. It makes me wonder if its doing what it's supposed to do. – jason dancks Apr 07 '14 at 14:31
  • Then I think you're mixing up your object with some pygame module items. What is it that you're actually trying to pass. A function should be able to use `pygame.font.Font` without passing pygame assuming the module has been imported into your code. – elParaguayo Apr 07 '14 at 15:14
  • Well I'm such a dumbass: I forgot to use coordinates relative to the size of the drawing surface – jason dancks Apr 07 '14 at 15:46
  • Ha. And the point I referred to wasn't an issue at all. I guess we're both dumbasses then! – elParaguayo Apr 07 '14 at 15:49

0 Answers0