I haven’t tested it on devices yet but I’m using a performance meter module for the Corona Simulator that I find very helpful
[url=[https://github.com/pancsoftware/performancemeter.git](https://github.com/pancsoftware/performancemeter.git)]
In my app I have 100 - 200 objects (life forms) interacting with one another and I thought it would be cool to introduce light and dark cycles. I made a sun module (sun.lua) and in it a sun rotates off screen around the viewable area. I move the sun with a method called “moveSun()”. moveSun() moves the sun in a circle around the center of the screen and returns the x and y positions of the sun as sine an cosine values for use in the object fill method - object.fill.effect.dirLightDirection = { x, y, z }
[url=http://docs.coronalabs.com/guide/graphics/effects.html]
[lua]
local sunTimer = timer.performWithDelay( 100, function() -- inline function repeats 10x/sec local physicsState = ui.getPhysicsState() -- get current physics state if (physicsState == "play") then -- if physics state is "play" e.i. not paused local sunX, sunY = sun.moveSun() --[[calls the moveSun() method from the sun module (require file) which: 1) rotates the sun around the center by a set number of degrees 2) compares the position of the sun to the center (in degrees) 3) converts postion degrees to radians and gets quadrant info for +/- values 4) math.cos(radians) = sunX 5) math.sin(radians) = sunY 6) returns sunX, sunY --]] for i=1,#somaList do -- somaList is a list that stores the objects if (somaList[i].alive == true) then -- if the object is not dead somaList[i].fill.effect.dirLightDirection = { sunX, sunY, 0.5 } -- x, y, z values for the Normal Map ; applied to each object end end end end, 0) -- end inline function and set repeat to infinite
[/lua]
My frame rates start of get little glitches when I get to about 100 objects and it becomes very noticeable by 150 objects.
Unfortunately, the method I wrote to fix the rotation problem I mentioned above decreases performance significantly. The frame rate glitches around 50 objects. I think I can find a way to refine it but, for my app, I doubt it will be clean enough to be useful. I’m thinking I will use the normal map to create a sense of depth that isn’t true to the scene lighting and then use object.soma.fill.effect.ambientLightIntensity to change the mood of the lighting.
Only people with a degree of art training or a high level of observation will notice this imperfection. With Hollywood lighting casting improbably shadows on everything we watch, I think most people are desensitized to true lighting and won’t notice my trickery ; )
I’m going to spend one more day on this n-map rotation problem and then I’m going to move onto the other tasks.
Let me know if you make any discoveries!
Jonathan