I have recently been tuning up my game and designing some basic menu screens and GUI elements. One API aspect I use frequently is the “reference points”, as in:
object:setReferencePoint(display.BottomRightReferencePoint)
Anybody who uses these knows how valuable they are to aligning text and other objects properly.
Then I remembered a little tip from the Optimization section of Corona’s docs…
_ Cache properties in a local variable
If you are constantly accessing a property of a table but not changing its value, then you should cache that value. There is a slight performance penalty to doing property lookups in a table. For objects created by Ansca’s api’s — such as the display object returned by display.newImage() — the penalty is even higher._
So I considered, can any API beginning with " display." be cached for a slight performance boost? Can somebody (Ansca) confirm this?
Most people already do (or should) cache their math functions in local variables, i.e. local cos = math.cos. This prevents a constant “lookup” of the cos function if you’re using it frequently, especially in a loop.
So why not the same for the " display." API?
I tested putting my reference points into local variables, as follows:
local centerLeft = display.CenterLeftReferencePoint --near top of file
--and further down, the call:
object:setReferencePoint(centerLeft)
This seems to work but I’m unsure if it results in any performance boost. In theory, it might only do so if you’re using this alignment principle alot, as in a large menu of many text items that must be aligned center-left.
Thoughts or opinions on this?
Brent
[import]uid: 9747 topic_id: 9016 reply_id: 309016[/import]
[import]uid: 52430 topic_id: 9016 reply_id: 32916[/import]