Tremendous performance loss when running on Android compared to iPhone

I’m developing a game (fairly simple with a couple of screens and a few sprites) mainly for iOS but yesterday I decided to test it on an actual Android device (Nexus One) and there’s a significant loss in performance compared to testing on an iPod touch.

I’m talking about 500-900 millisecond response time when the screen is tapped on Android compared to instant response on iOS. In addition, when I use logcat to see what’s going on, it outputs things about “Grow Memory Heap”.

Any idea why this is happening?

Thanks! [import]uid: 8446 topic_id: 3395 reply_id: 303395[/import]

I’m not sure what’s going on there. Can you elaborate any on your app is doing, or provide a code sample/test case?

Tim [import]uid: 8196 topic_id: 3395 reply_id: 10154[/import]

Hi Tim, the structure of my project goes like this:

  • Main menu
  • Play
  • Game Screen
  • Screen has one background image
  • There’s an init() method that creates the initial 4 enemy sprites and adds them to a table (enemyArray)
  • The sprites have 4 frames each and they animate at about 600ms, and they contain an event listener on 'tap
  • There’s the game loop that moves the sprites and checks if they’re “dead” and should be removed

[lua]-- Function when the sprite is ‘tapped’
local killEnemy = function( event )
if event.phase == ‘began’ then
local target = event.target
target.taps = target.taps + 1
if(target.taps >= target.tapsToKill) then
target.isDead = true
end
end
end

– Main game loop
local gameLoop = function( event )
for i,obj in pairs(enemyArray) do
if obj.isDead == true then
table.remove(enemyArray, i)
obj:removeSelf()
else
obj.x = obj.x + 0.10
end
if obj.x > display.contentWidth then
obj.isDead = true
end
end

end[/lua]

I’m using the latest Corona Game edition by the way.

Thanks. [import]uid: 8446 topic_id: 3395 reply_id: 10182[/import]

one thing you might want to look at is that you’re running obj:removeSelf then testing if obj.x, which doesnt make sense, since you’ve just removed it. move the check for obj.x into your else function.

eg:

[lua]-- Main game loop
local gameLoop = function( event )

local newX

for i,obj in pairs(enemyArray) do
if obj.isDead == true then
table.remove(enemyArray, i)
obj:removeSelf()
else
newX = obj.x + 0.10

if obj.x > display.contentWidth then
obj.isDead = true
else
obj.x = newX
end

end

end

end[/lua]
[import]uid: 6645 topic_id: 3395 reply_id: 10264[/import]

@jmp909, you’re correct, I had pasted in the forum the obj.x check on the wrong spot, it should’ve been contained within the else statement as I had it in my original code. So no changes in performance here, the problem is still persisting. [import]uid: 8446 topic_id: 3395 reply_id: 10300[/import]

rather than have a game loop check for objects being killed every frame you could just do it in your hit check, but with a delay, as the physics engine doesn’t like stuff being changed within a hit event. so your hit function would be

[lua]local killEnemy = function( event )
if event.phase == ‘ended’ then
local target = event.target
target.taps = target.taps + 1
if(target.taps >= target.tapsToKill) and
(target.isDead == false) then
target.isDead = true
timer.performWithDelay(5, function() target:removeSelf()
end)
end
end[/lua]
that could optimize things a little…
(i left the isDead = true in there to trap the case where another tap is registered before the target is removed…)
[import]uid: 118333 topic_id: 3395 reply_id: 102139[/import]