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?

[import]uid: 39031 topic_id: 18065 reply_id: 318065[/import]

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

[lua]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[/lua] [import]uid: 12482 topic_id: 18065 reply_id: 69062[/import]

Didn’t realize you could get height and width value from a text element!
I 'll give it a try.
Thanks!! [import]uid: 39031 topic_id: 18065 reply_id: 69064[/import]

you welcome
:slight_smile: [import]uid: 12482 topic_id: 18065 reply_id: 69076[/import]