Stroke on Text

Is it possible in Corona? Using Images with a stroke for each letter would be possible, but the kerning/spacing inbetween each letter would look horrible…

And it seems that every game has it :> [import]uid: 13097 topic_id: 11072 reply_id: 311072[/import]

Here is my first implementation, but it needs some optimization

[code]
newText = function(str, left, top, font, size, color, strokewidth, strokecolor)
local c1
local c2
local bg
local txt
local t = display.newGroup()

for c1 = left-math.abs(strokewidth), left+math.abs(strokewidth) do
for c2 = top-math.abs(strokewidth), top+math.abs(strokewidth) do
bg = display.newText(str, c1, c2, font, size)
bg:setTextColor(strokecolor[1], strokecolor[2], strokecolor[3])

t:insert(bg)
end
end

txt = display.newText(str, left, top, font, size)
txt:setTextColor(color)
t:insert(txt)

return t
end
[/code] [import]uid: 21692 topic_id: 11072 reply_id: 76262[/import]

thank you for your help, blue box! it would be amazing to optimize the code to make it faster because now, unfortunately, it’s a bit slow…however well done. i hope you’ll optimize it! :slight_smile: [import]uid: 63063 topic_id: 11072 reply_id: 76292[/import]

I think it would be faster if it’s integrated directly in C++ inside the SDK.

btw, if you use a lower strokewidth it’s fast enough, i’m currently using it for level select (25 in one page) and it takes 2secs with 1px stroke and up to 5 secs with 3px =(

Andy
[import]uid: 21692 topic_id: 11072 reply_id: 76294[/import]

ok, thanks a lot! we should tell it to corona directors! [import]uid: 63063 topic_id: 11072 reply_id: 76384[/import]

Awesome! Saved my life :wink:

Follows a version slightly improved and adapted to g2.0

local newText = function(str, font, size, color, strokewidth, strokecolor) local bg local t = display.newGroup() t.anchorChildren = true for c1 = -strokewidth, strokewidth do for c2 = -strokewidth, strokewidth do if c1 ~= 0 or c2 ~= 0 then bg = display.newText({parent=t, text=str, x=c1, y=c2, font=font, fontSize=size}) bg.fill = strokecolor end end end local txt = display.newText({parent=t, text=str, font=font, fontSize=size}) txt.fill = color return t end

Awesome! Saved my life :wink:

Follows a version slightly improved and adapted to g2.0

local newText = function(str, font, size, color, strokewidth, strokecolor) local bg local t = display.newGroup() t.anchorChildren = true for c1 = -strokewidth, strokewidth do for c2 = -strokewidth, strokewidth do if c1 ~= 0 or c2 ~= 0 then bg = display.newText({parent=t, text=str, x=c1, y=c2, font=font, fontSize=size}) bg.fill = strokecolor end end end local txt = display.newText({parent=t, text=str, font=font, fontSize=size}) txt.fill = color return t end