I’m really concerned by the performance I’m getting on my iPhone 4. I have a *very* simple game, but it has a hard time maintaining even 30FPS. On average, it runs closer to 15-20FPS.
I do have a large number of display objects in the scene (around 85). 50 of those display objects have a simple script attached to them that gradually fades them in and out over time. So on each frame, I’m looping over my table of those 50 objects and adjusting their alpha value slightly.
I’ve tried reducing the number of fading objects, and even with 10 fading objects the performance is still awful.
What are my options here? Would texture atlasing help performance at all? I’m running out of ideas…
Here are the relevant chunks of code in case that helps:
main.lua
local previousTime = system.getTimer()
local function Update( event )
local currentTime = system.getTimer()
local dt = currentTime - previousTime
previousTime = currentTime
background.Update( dt )
moon01:Update( dt )
cloud01:Update( dt )
cloud02:Update( dt )
cloud03:Update( dt )
end
background.lua
background.Update = function( dt )
local overlays = background.overlays
for i = 1, #overlays do
overlays[i]:Update( dt )
end
end
overlay.lua
[code]
function overlay:Update( dt )
local getTimer = system.getTimer
local texture = self.texture
if self.delay > 0 then
self.delay = self.delay - dt
if self.delay <= 0 then self.startingTime = getTimer() end
return
end
if self.fadingIn then
local newAlpha = ( getTimer() - self.startingTime ) / ( self.transitionTime )
if newAlpha > 1 then
texture.alpha = 1
self.startingTime = system.getTimer()
self.delay = math.random( 0, 10000 )
self.fadingIn = false
else
texture.alpha = newAlpha
end
else
local newAlpha = 1 - (( getTimer() - self.startingTime ) / ( self.transitionTime ))
if newAlpha < 0 then
texture.alpha = 0
self.startingTime = getTimer()
self.delay = math.random( 0, 10000 )
self.fadingIn = true
else
texture.alpha = newAlpha
end
end
end
[/code] [import]uid: 82003 topic_id: 20749 reply_id: 320749[/import]
I’ll see if I can try reducing the size of the textures…