I’ve been trying to create a feature where the value of a current counter is drawn on screen and grows until it reaches a certain size then disappears. It’s a visual indicator to the user that an event has happened. Think of it as the reverse of a countdown timer. For some reason, the transition performance on device (Android 4.03 at least) has been utterly terrible. Is there a huge performance penalty for scaling text objects compared to scaling image display objects?
In the following code, I’m using storyboard so the text object is forward declared before any other functions. The createText function simply modifies the existing text object. The createScene function sets up the text object and adds it to the display group. The createText function is called on a touch handler whenever the user successfully touches an object.
[lua]local expandingText
local function createText(myString)
–Redraw a text object that expands and disappears
if expandingText.transition then transition.cancel(expandingText.transition) end
local options = {
time = 600,
size = expandingText.original * 10,
transition = easing.outQuad,
onComplete = function()
expandingText.transition = nil
expandingText.size = expandingText.original
expandingText.alpha = 0
end
}
expandingText.size = expandingText.original
expandingText.text = myString
expandingText.alpha = 0.2
expandingText.transition = transition.to(expandingText, options)
end
function scene:createScene(event)
local group = self.view
expandingText = display.newText(“0”, display.contentCenterX, display.contentCenterY, fontName, 32)
expandingText:setTextColor(150,150,150)
expandingText.original = expandingText.size
expandingText.alpha = 0
group:insert(expandingText)
end[/lua]
The display seems to slow down as the text is rendered larger and larger. If the function is called repeatedly, the slow down is unbearable. I am currently modifying one text object since I thought it would be faster than creating a new text object each time. While I liked the appearance of creating a new text object each time, the poor performance on device led me to try and refactor the code to use one object. I also removed the alpha transition (again looked great) in the hopes of finding additional performance.
What suggestions do you have for improving the performance of this function? Thanks in advance! [import]uid: 168249 topic_id: 32464 reply_id: 332464[/import]