I have a textfield for my score counter and if I call setText("XXX") each frame to update the score the frame rate drops a lot if I have about 15-20 moving sprites on the screen. I also noticed in Xcode it shows these two messages whenever setText is called:
log: Inserting *unnamed* to the texture cache. Total memory is 9804 KB.
log: Deleting *unnamed* from the texture memory. Total memory is 9796 KB.
I've tried setting the text every 5 or 10 frames and that does seem to help but the score doesn't update as much as I'd like it to.
I initialize the TextField like this inside of a scene:
local font = TTFont.new("fonts/Averia-Regular.ttf", 28)
scoreLabel = TextField.new(font)
scoreLabel:setText("00")
scoreLabel:setPosition(5, scoreLabel:getHeight() + 5)
self:addChild(scoreLabel) |
Then, in the game loop I set the score like this:
scoreLabel:setText(self.score) |
where score is a number amount. Does anything look wrong or should be done differently?
Thanks
Comments
However - what you could do would be to just have ten basic bitmaps to represent each number and then write a simple function to take the score value and turn it into a number of sprites.
On a side note - one thing I always used to do in my games was maintain two scores, the real one that represented the actual score for things like extra life checking etc, and the displayed one. Each frame I'd work out the difference between the displayed score and real score and then add 1/8th of the difference (diff >> 3) to the displayed score (obviously making the two equal if the difference was < 8) and the convert the displayed score into sprites for rendering.
It worked really well in action / arcade games where you could get a big score bonus as you'd then see the displayed score "roll" up to the desired value rather than just jumping and added a little extra bit of polish
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
http://wujitouch.com
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
http://www.giderosmobile.com/forum/discussion/comment/4915#Comment_4915
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive