swap sprite animation

Hi how can i change the animation from “hammerRightStill” to “hammerRightHmmer” on a event ? 

-- Hammer start local HammerRight = { width = 75, height = 54, numFrames = 10, sheetContentWidth = 750, sheetContentHeight = 54, } local hammerRightinfo = graphics.newImageSheet( "img/hammer.png", HammerRight ) local hammerRightStill = { name="normal3", frames= {1}, time = 600, loopCount = 0 } local hammerRightHmmer = { name="normal4", frames= {1,2,3,4,5,6,7,8,9,10}, time = 600, loopCount = 1 } local screenGroup = self.view hammerRight = display.newSprite( hammerRightinfo, hammerRightStill) shape = { -5,-15, 15,-15, 1, 16, -10,16, } hammerRight.x = display.contentWidth/2 + 16 hammerRight.y = display.contentHeight/2 hammerRight:play() hammerRight.collided = true hammerRight.name = "hammerRight" hammerRight:setReferencePoint( display.CenterLeftReferencePoint ) hammerRight.isVisible = true-- false hammerRight.isFixedRotation=true screenGroup:insert(hammerRight) -- Hammer stop

Define your sprite sequences like this:

 [lua]

local sequenceData = {

            { name = “idle”, start = 1, count = 8, time = 600},

            { name = “spin1”, start = 3, count = 2, time = 100, loopCount = 1 },

            { name = “spin2”, start = 5, count = 2, time = 100, loopCount = 1 },

            { name = “dead”, start = 7, count = 3, time = 300, loopCount = 1 },

            { name = “shoot”, start = 10, count = 2, time = 150, loopCount = 1 },

            { name = “idles”, start = 1+11, count = 2, time = 200 },

            { name = “spin1s”, start = 3+11, count = 2, time = 100, loopCount = 1 },

            { name = “spin2s”, start = 5+11, count = 2, time = 100, loopCount = 1 },

            { name = “deads”, start = 7+11, count = 3, time = 300, loopCount = 1 },

            { name = “shoots”, start = 10+11, count = 2, time = 150, loopCount = 1 }

        }

        local sprite = display.newSprite(sprites, sequenceData)

[/lua]

Then switch between them like this:

[lua]

sprite:setSequence(“dead”)

sprite:play()

[/lua]

Works like a charm Nick :D 

Define your sprite sequences like this:

 [lua]

local sequenceData = {

            { name = “idle”, start = 1, count = 8, time = 600},

            { name = “spin1”, start = 3, count = 2, time = 100, loopCount = 1 },

            { name = “spin2”, start = 5, count = 2, time = 100, loopCount = 1 },

            { name = “dead”, start = 7, count = 3, time = 300, loopCount = 1 },

            { name = “shoot”, start = 10, count = 2, time = 150, loopCount = 1 },

            { name = “idles”, start = 1+11, count = 2, time = 200 },

            { name = “spin1s”, start = 3+11, count = 2, time = 100, loopCount = 1 },

            { name = “spin2s”, start = 5+11, count = 2, time = 100, loopCount = 1 },

            { name = “deads”, start = 7+11, count = 3, time = 300, loopCount = 1 },

            { name = “shoots”, start = 10+11, count = 2, time = 150, loopCount = 1 }

        }

        local sprite = display.newSprite(sprites, sequenceData)

[/lua]

Then switch between them like this:

[lua]

sprite:setSequence(“dead”)

sprite:play()

[/lua]

Works like a charm Nick :D