Change sequence data for sprite

I’m new to Corona and Lua and I’m considering rewriting an iOS app I wrote.

I have some code that works that loads a simple animation:

local sheetData = { width=270, height=250, numFrames=12, sheetContentWidth=540, sheetContentHeight=1500 } local mySheet = graphics.newImageSheet( "radar.png", sheetData ) local sequenceData = {     { name = "normalRun", start=1, count=12, time=800, loopCount=1 }, } local animation = display.newSprite( mySheet, sequenceData )

Can I now go back and alter the sequenceData variables? For example, maybe I want loopCount to be 2 based on a preference for the app.

I tried this and I can see in the terminal that the value changed, but it did not cause the animation to loop twice:

sequenceData[1].loopCount=2 print ("Value="..sequenceData[1].loopCount)

I’m sure it’s something simple. Can anyone point me in the right direction?

Haven’t try modifying this parameters but they can be used only when creating sprite and are no more used after. So when you modify it, it changes value but sprite is not using it any more after being creates. Cannot you do

[lua]
local option = 1
local sequence

if option == 1 then
sequence = {…}
elseif option == 2 then
sequence = {…}
else
sequence = {…}
end

local sprite = display.newSprite(mySheet, sequence)
[/lua]
?

Hi @fly4,

@piotrz55 is correct: you can’t change most of the sequence details of a sprite after setting it up. You could, however, tell the sprite to stop after 1 “loop” by using sprite event listeners, i.e. set it up to loop indefinitely, then after one loop (or two, or whatever) make it pause or go back to another frame or something like that.

Brent

Thanks folks. I think I’ll either setup multiple sequences or setup event listeners. Prob multiple sequences to keep it simple.

Really diggin’ Corona!

Haven’t try modifying this parameters but they can be used only when creating sprite and are no more used after. So when you modify it, it changes value but sprite is not using it any more after being creates. Cannot you do

[lua]
local option = 1
local sequence

if option == 1 then
sequence = {…}
elseif option == 2 then
sequence = {…}
else
sequence = {…}
end

local sprite = display.newSprite(mySheet, sequence)
[/lua]
?

Hi @fly4,

@piotrz55 is correct: you can’t change most of the sequence details of a sprite after setting it up. You could, however, tell the sprite to stop after 1 “loop” by using sprite event listeners, i.e. set it up to loop indefinitely, then after one loop (or two, or whatever) make it pause or go back to another frame or something like that.

Brent

Thanks folks. I think I’ll either setup multiple sequences or setup event listeners. Prob multiple sequences to keep it simple.

Really diggin’ Corona!