Self adjustable text background box?

I would like to put a title for each level that appears for a couple of seconds. Since the wallpaper and the title text size change from level to level, I want to put a 80% opaque black rectangle behind the white text, and make the black rectangle auto-adjusting to the text size (since I rather not manually create the text bg one by one).
Is this possible?

not sure what u r looking for but something like this can help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local function newTextinblackRect(str,x,y,font,height)
        local myText = display.newText(str,x,y,font,height)
        local width = myText.width
        local height = myText.height
        local rect = display.newRect(x-5,y-5,width+10,height+10)
        rect:setFillColor(255,0,0,100)
        local myGroup = display.newGroup()
        myGroup:insert(rect)
        myGroup:insert(myText)
        return myGroup
 
end
 
local function callMe(e)
        e.target:removeSelf()
end
for i=1,10 do
        myText = newTextinblackRect(math.random(1000),10*i,30*2*i,nil,36)
        myText:addEventListener("tap",callMe)
end

Didn't realize you could get height and width value from a text element!
I 'll give it a try.
Thanks!!

you welcome

:)

views:1370 update:2011/11/25 8:45:21
corona forums © 2003-2011