time-based animation stutter

I am animating 24 static sprite objects on the screen using time-based animation and am experiencing intermittent stuttering in the animation. The animation is simple - moving objects on a linear-x path and restarting the object on the opposite side of the screen when the object has crossed the screen boundary. Even reducing the set down to 1 object still produces stuttering in the animation when viewed on my iPhone 4. Is there something that I’m doing wrong here?

[code]
function animateStream(event)
local x
local y
local row
local curl
local bgIdx
local lIdx
local tDelta = system.getTimer() - tPrevious
local delta = lSpeed * (60 / tDelta)

tPrevious = system.getTimer()

for i, value in ipairs(l.stream) do
x = l.stream[i].x
y = l.stream[i].y
row = l.stream[i].row

if (row == animateRowsLeft[1] or row == animateRowsLeft[2]) then
x = x + delta
else
x = x - delta
end

if (x > tileThreshold or x < xTileX) then
bgIdx = random(1, 20)
lIdx = random(1, #l.matrix)

if (bgIdx > 3) then
bgIdx = 1
end

l.stream[i][1].currentFrame = bgIdx
l.stream[i][2].currentFrame = lIdx
l.stream[i].l = l.matrix[lIdx]
l.stream[i].lIdx = lIdx
l.stream[i].type = bgIdx

if (x > tileThreshold) then
x = xTileX + delta
else
x = tileThreshold - delta
end
l.stream[i].alpha = 1
l.stream[i][2].alpha = 1
end

l.stream[i].x = x
l.stream[i].y = y
l.stream[i].snapX = x
l.stream[i].row = row
end
end
function gameLoop(event)
– In my project there is a bit of logic here that manipulates variables
animateStream(event)
end
– I am using performWithDelay() instead of an enterframe as suggested in another forum post
– concerning a similar issue in animation stuttering using transition.to()

timerStash.gameLoop = timer.performWithDelay(2, gameLoop, 0)
[/code] [import]uid: 23583 topic_id: 16541 reply_id: 316541[/import]

Have you tried using enterFrame? I know you say why you don’t, but you might just solve this using enterFrame. I for one wouldn’t even think of NOT using enterFrame, as the enterFrame event is made and optimised specifically for this kind of game logic. [import]uid: 70134 topic_id: 16541 reply_id: 61816[/import]

enterFrame is what I started with. I just tried it again. Still stutters. using performWithDelay() seems to calm down the stuttering a little.

Could the problem be that I’m repositioning 24 items on each frame?

[import]uid: 23583 topic_id: 16541 reply_id: 61899[/import]

Same problem. Just posted it about it somewhere else, and I might reposition up to 100 objects a frame :-s

So you’re saying performWithDelay doesn’t solve the problem? Should I try it?

Thanks [import]uid: 91771 topic_id: 16541 reply_id: 62732[/import]

I just tried PerformWithDelay - stutters more :s [import]uid: 91771 topic_id: 16541 reply_id: 62746[/import]

Does your app run at 30 or 60 FPS?

Just guessing, but it doesn’t seem like the delay you are using matches the rate at which the screen is refreshed.

I use enterFrame, and I find that I can animation about 100 sprites without impacting the frame rate for an app running at 30 FPS on a newer iDevice. If I up the app FPS to 60, I find that may code is causing the FPS to drop. [import]uid: 67839 topic_id: 16541 reply_id: 62752[/import]

I rebooted my phone and now the stuttering seems to have disappeared but I’m not confident that the issue is resolved. My game will be in beta in a few days so more testing should reveal if it’s still an issue. That being said, I would like to know if there is a more efficient or clever way to animate 20+ objects on the screen. For example, a game like Osmosis or a bullet hell type of game.

What’s interesting is previously I built a Tiny Wings type game that moved and scaled a huge background image and I never experienced any stuttering in the animation. I’m starting to think that the code for animating objects using the physics engine is more efficient than writing custom animation algorithms in LUA.

Thoughts from the Ansca team? [import]uid: 23583 topic_id: 16541 reply_id: 62753[/import]

Are you using iOS 5? I’ve noticed some very old games that had no issues before get animation stutters… A little far fetched, but it could fit to “reboot helps” description. [import]uid: 46570 topic_id: 16541 reply_id: 62824[/import]

Hey,

I have an iPhone 4 Verizon, OS Version: 4.2.10.

Today I tried moving a box. Only a box, on a black screen, and it stutters!

It doesn’t look ‘clean’ and smooth at all.

I tried to move it with:

  1. EnterFrame:
    a. Translate
    b. X = X + deltaX
  2. transition.to

Nothing looks nice enough :frowning:

Any ideas? Ansca? :smiley: Help :smiley: [import]uid: 91771 topic_id: 16541 reply_id: 62826[/import]

I’ve been testing in IOS 5. FPS set to 60 in config.lua. [import]uid: 23583 topic_id: 16541 reply_id: 62952[/import]

i have the same problem i am using transition.to (increasing y and x by number value to make my objects moved in path) also my objects numbers in screen does not exceeds 14 objects i am using movieclip to move the animated frames (each object have 4 frames that played by obj:play method )

then objects moved using transition function and on complete also i am calling the same function i am feeling when run the game in real android device that object stuck in screen for less than 20ms not all the time and then completing its transition …
also i tried to measure the fps on my game on the start up of game its between 23-27 and its seems to be constant in these range the minimum fps in last frames when (active objects on the screen reach 12 ) fps will be 17
BTW, using spritesheet instead of movieclip also suffer from the same problem i tried it) no difference

so please help me i have to know where is the actual problem is it from transition function or what ???

i have modularize my code into modules does this make problem
but i don’t think that also moving one object on the screen have not smoothly movement as it should be

with respect
thanks in advance …

[import]uid: 74537 topic_id: 16541 reply_id: 62953[/import]

I would use enterframe without a timer.performWithDelay. set your config file to use 60 fps and enterframe should execute about 60 times a second.

From there you can control your objects speed (pixels per second).

local object.speed = 1  
  
local function animate(event)  
 object.x = object.x - object.speed  
end  
Runtime:addEventListener( "enterFrame", animate )  

Above the object will move to the lefts at 60 pixels per second. If I change the object.speed to 2 then the object will be moving at about 120 pixels per second.

Hope this helps. There’s probably a hundred other ways to do this but, I find this way smooth.

[import]uid: 38820 topic_id: 16541 reply_id: 62970[/import]

@glennbjr thank you but this will not run in all devices

60 fps run in new devices what about if the android mobile does not mach the specification to run 60 fps games ?? [import]uid: 74537 topic_id: 16541 reply_id: 62975[/import]

you could try 30 fps. I known on my android device Galaxy S animation is not as smooth with 30 fps. So I always use 60 fps but, that’s my choice. It’s up to you. [import]uid: 38820 topic_id: 16541 reply_id: 62978[/import]

I realize this probably won’t have much of an impact on the performance, but I believe using ipairs (line 13) isn’t as efficient as using a for do loop.

e.g. instead of

[lua]for i, value in ipairs(l.stream) do[/lua]

try

[lua]for i=0, #l.stream, do
local item = l.stream[i][/lua]

according to this article, using ipairs takes more than twice as long. [import]uid: 49447 topic_id: 16541 reply_id: 62980[/import]

@producerism thank you for sharing your experience

but there is huge problem on moving objects using transition.to()

supported by corona look at this post

link [import]uid: 74537 topic_id: 16541 reply_id: 62982[/import]

i have the same problem, is there any fix in corona for it ? [import]uid: 79884 topic_id: 16541 reply_id: 62983[/import]