Sprite sequences

Hi! Im trying to get a character to stare, and then blink once every 5 seconds, however he end up blinking constantly.
How can I get my character to automatically swich between my sequenceData?

This is my code:

[lua]local sheetData = { width=291.49, height=177.49, numFrames=6, sheetContentWidth=1748, sheetContentHeight=177 }

local sequenceData = {
    { name=“stare”, start=1, count=1, time=5000, loopCount = 1 },
    { name=“blink”, start=1, count=6, time=250, loopCount = 1, loopDirection = “bounce” },
    { name=“test”, start=3, count=6, time=1000, loopCount = 2 },
}

local mySheet = graphics.newImageSheet( “blink.png”, sheetData )

local eyes = display.newSprite( mySheet, sequenceData )
    eyes.x = display.contentCenterX
    eyes.y = display.contentCenterY
    eyes:play()

local function spriteListener( event )

    local blinking = event.target
    if ( event.phase == “ended” ) then
        blinking:setSequence( “blink” )
        blinking:play()
    end
end
eyes:addEventListener( “sprite”, spriteListener )[/lua]

Thank you

You are starting the sprite and when it gets completed, the sprite listener gets called again which tells Corona to set the sequence and then start it all over again with blinking:play() so the same sprite will be run over and over again. There is no one telling the sprite to start the “stare” animation.

Try this:

local sheetData = { width=291.49, height=177.49, numFrames=6, sheetContentWidth=1748, sheetContentHeight=177 } local sequenceData = { { name="stare", start=1, count=1, time=5000, loopCount = 1 }, { name="blink", start=1, count=6, time=250, loopCount = 1, loopDirection = "bounce" }, { name="test", start=3, count=6, time=1000, loopCount = 2 }, } local mySheet = graphics.newImageSheet( "blink.png", sheetData ) local eyes = display.newSprite( mySheet, sequenceData ) eyes.x = display.contentCenterX eyes.y = display.contentCenterY eyes:play() local current\_sequence = "stare" local function spriteListener( event ) local spr = event.target if ( event.phase == "ended" ) then if current\_sequence == "stare" then current\_sequence = "blink" spr:setSequence( "blink" ) elseif current\_sequence == "blink" then current\_sequence = "stare" spr:setSequence( "stare" ) end end spr:play() end eyes:addEventListener( "sprite", spriteListener )

Hey thank you so much!! It works just as intended.

Was trying to figure it out all day. Cheers!

I’ll try to integrate the Test sequence as well.

You are starting the sprite and when it gets completed, the sprite listener gets called again which tells Corona to set the sequence and then start it all over again with blinking:play() so the same sprite will be run over and over again. There is no one telling the sprite to start the “stare” animation.

Try this:

local sheetData = { width=291.49, height=177.49, numFrames=6, sheetContentWidth=1748, sheetContentHeight=177 } local sequenceData = { { name="stare", start=1, count=1, time=5000, loopCount = 1 }, { name="blink", start=1, count=6, time=250, loopCount = 1, loopDirection = "bounce" }, { name="test", start=3, count=6, time=1000, loopCount = 2 }, } local mySheet = graphics.newImageSheet( "blink.png", sheetData ) local eyes = display.newSprite( mySheet, sequenceData ) eyes.x = display.contentCenterX eyes.y = display.contentCenterY eyes:play() local current\_sequence = "stare" local function spriteListener( event ) local spr = event.target if ( event.phase == "ended" ) then if current\_sequence == "stare" then current\_sequence = "blink" spr:setSequence( "blink" ) elseif current\_sequence == "blink" then current\_sequence = "stare" spr:setSequence( "stare" ) end end spr:play() end eyes:addEventListener( "sprite", spriteListener )

Hey thank you so much!! It works just as intended.

Was trying to figure it out all day. Cheers!

I’ll try to integrate the Test sequence as well.