Hi.
OK so I have finally narrowed it down to a custom function I wrote to add a stroke to some text objects, players coin balance for example. (Is there a better way or an API for this? I tried textObject.strokeWidth etc. however it looks funny when it renders it on screen, the text stroke is all lumpy and looks bad).
Anyway, the function is called several times per second sometimes (when the balance is incremented after a win for example. I assume the nilling out of the stroke objects worked however maybe I have to also nil out the text object itself each cycle? Not quite sure.
Here is the function I wrote: (sometimes it is called on each frame for about up to 40 or so frames - therein lies the performance issue I believe!)
function strokeText(target,strokeColor,strokeWidth, textSize)
–[[
display.remove(target.strokeBack1) --This is the same as calling object:removeSelf(), but will first check if the object exists before attempting to remove.
display.remove(target.strokeBack2)
display.remove(target.strokeBack3)
display.remove(target.strokeBack4)
display.remove(target.strokeBack5)
display.remove(target.strokeBack6)
display.remove(target.strokeBack7)
display.remove(target.strokeBack8)
target.strokeBack1 = nil target.strokeBack2 = nil target.strokeBack3 = nil target.strokeBack4 = nil target.strokeBack5 = nil
target.strokeBack6 = nil target.strokeBack7 = nil target.strokeBack8 = nil
–
– if target.strokeBack1 ~= nil then target.strokeBack1:removeSelf() target.strokeBack1 = nil end
– if target.strokeBack2 ~= nil then target.strokeBack2:removeSelf() target.strokeBack2 = nil end
– if target.strokeBack3 ~= nil then target.strokeBack3:removeSelf() target.strokeBack3 = nil end
– if target.strokeBack4 ~= nil then target.strokeBack4:removeSelf() target.strokeBack4 = nil end
– if target.strokeBack5 ~= nil then target.strokeBack5:removeSelf() target.strokeBack5 = nil end
– if target.strokeBack6 ~= nil then target.strokeBack6:removeSelf() target.strokeBack6 = nil end
– if target.strokeBack7 ~= nil then target.strokeBack7:removeSelf() target.strokeBack7 = nil end
– if target.strokeBack8 ~= nil then target.strokeBack8:removeSelf() target.strokeBack8 = nil end
local offset1 = strokeWidth
–local offset2 = offset1
target.strokeBack1 = display.newText(target.parent,target.text,target.x+offset1, target.y+offset1,fontStyle,textSize)
target.strokeBack1:setFillColor(unpack(strokeColor))
target.strokeBack1:toFront()
target.strokeBack2 = display.newText(target.parent,target.text,target.x-offset1, target.y-offset1,fontStyle,textSize)
target.strokeBack2:setFillColor(unpack(strokeColor))
target.strokeBack2:toFront()
target.strokeBack3 = display.newText(target.parent,target.text,target.x+offset1, target.y-offset1,fontStyle,textSize)
target.strokeBack3:setFillColor(unpack(strokeColor))
target.strokeBack3:toFront()
target.strokeBack4 = display.newText(target.parent,target.text,target.x-offset1, target.y+offset1,fontStyle,textSize)
target.strokeBack4:setFillColor(unpack(strokeColor))
target.strokeBack4:toFront()
target.strokeBack5 = display.newText(target.parent,target.text,target.x, target.y+offset1,fontStyle,textSize)
target.strokeBack5:setFillColor(unpack(strokeColor))
target.strokeBack5:toFront()
target.strokeBack6 = display.newText(target.parent,target.text,target.x, target.y-offset1,fontStyle,textSize)
target.strokeBack6:setFillColor(unpack(strokeColor))
target.strokeBack6:toFront()
target.strokeBack7 = display.newText(target.parent,target.text,target.x-offset1, target.y,fontStyle,textSize)
target.strokeBack7:setFillColor(unpack(strokeColor))
target.strokeBack7:toFront()
target.strokeBack8 = display.newText(target.parent,target.text,target.x+offset1, target.y,fontStyle,textSize)
target.strokeBack8:setFillColor(unpack(strokeColor))
target.strokeBack8:toFront()
target:toFront()
return target.strokeBack1, target.strokeBack2, target.strokeBack3, target.strokeBack4, target.strokeBack5, target.strokeBack6, target.strokeBack7, target.strokeBack8
–]]
–print(“stroke text”)
–return true
end
There’s probably a better way to do this but that’s what I came up with so far… LOL
Do I need to pass in the text object and then nil out the original text object or is this just going to always mess up the performance and I should just avoid the text stroke?
What about something like target = nil and then target.text = “textPassedIn” ?
I don;t know.
I appreciate all your help.
Cheers!