Play a sequence once

Hey guys,

I’m not sure whatI’m doing wrong with my sprite sheet.I want the “cowBeaming”  sequence to play only once,but it keeps repetaing. The sequence is triggered by a collision event.I tried to create another collision function (event.phase == “ended”)  to stop the cowBeaming sequence,but it didn’t work.

Got any ideas?

Thanks!

local sheetData = {width = 100,height = 100,numFrames = 14,sheetContentWidth = 200,sheetContentHeight = 700} local mySheet = graphics.newImageSheet ("cow.png",sheetData) local sequenceData = { {name = "cowWalking",start = 1,count = 8,time = 1300,loopcount = 0}, {name = "cowBeaming",frames = {9,10,11,12,13,14},time = 1000,loopcount = 1} } local cow = display.newSprite (mySheet,sequenceData) cow.rotation = 90 cow.x = 30 cow.y = 450 cow:setSequence ("cowWalking") cow:play() physics.addBody (cow,"static",{radius = 15}) cow.isSensor = true cow:setLinearVelocity (0,0) local function two (event) if cow.y == 450 then cow.xScale = 1 transition.to(cow,{time = 16000,y = 7}) elseif cow.y == 7 then cow.xScale = -1 transition.to (cow,{time = 16000,y = 450}) end end timer.performWithDelay (100,two,0) local function cowCollision (event) if event.phase == "began" then cow:setSequence ("cowBeaming") cow:play() end end cow:addEventListener ("collision",cowCollision) group:insert (cow)

Hi @bogdanmocanu2,

This is a simple syntax error… you didn’t specify the loop count properly in case-sensitivity.

INCORRECT (what you coded): 

loopcount

CORRECT:

loopCount

Change that and everything should work. :slight_smile:

Brent

Hi Brent,

  Thank you for your help.

  Also can you please tell me why my collision event is triggered only once or twice in this chunk of code?After the collision event,I want the cow to be at y=400 and to play the cowWalking animation.But the code works only once,or twice,the collision event seems like it has removed itself.

Regards,

Bogdan

local sheetData = {width = 100,height = 100,numFrames = 14,sheetContentWidth = 200,sheetContentHeight = 700} local mySheet = graphics.newImageSheet ("cow.png",sheetData) local sequenceData = { {name = "cowWalking",start = 1,count = 8,time = 1300,loopCount = 0}, {name = "cowBeaming",frames = {9,10,11,12,13,14},time = 1000,loopCount = 1} } local cow = display.newSprite (mySheet,sequenceData) cow.rotation = 90 cow.x = 30 cow.y = 450 cow:setSequence ("cowWalking") cow:play() physics.addBody (cow,"static",{radius = 20}) cow.isSensor = true cow:setLinearVelocity (0,0) local function cowMovement (self,event) if self.y \<= 20 then self.y = 400 self:setSequence ("cowWalking") self:play() else self.y = self.y - 1.1 end end local function cowCollision (event) if event.phase == "began" then cow:setSequence ("cowBeaming") cow:play() end end cow:addEventListener ("collision",cowCollision) cow.enterFrame = cowMovement Runtime:addEventListener ("enterFrame",cow)

Hi @bogdanmocanu2,

This is a simple syntax error… you didn’t specify the loop count properly in case-sensitivity.

INCORRECT (what you coded): 

loopcount

CORRECT:

loopCount

Change that and everything should work. :slight_smile:

Brent

Hi Brent,

  Thank you for your help.

  Also can you please tell me why my collision event is triggered only once or twice in this chunk of code?After the collision event,I want the cow to be at y=400 and to play the cowWalking animation.But the code works only once,or twice,the collision event seems like it has removed itself.

Regards,

Bogdan

local sheetData = {width = 100,height = 100,numFrames = 14,sheetContentWidth = 200,sheetContentHeight = 700} local mySheet = graphics.newImageSheet ("cow.png",sheetData) local sequenceData = { {name = "cowWalking",start = 1,count = 8,time = 1300,loopCount = 0}, {name = "cowBeaming",frames = {9,10,11,12,13,14},time = 1000,loopCount = 1} } local cow = display.newSprite (mySheet,sequenceData) cow.rotation = 90 cow.x = 30 cow.y = 450 cow:setSequence ("cowWalking") cow:play() physics.addBody (cow,"static",{radius = 20}) cow.isSensor = true cow:setLinearVelocity (0,0) local function cowMovement (self,event) if self.y \<= 20 then self.y = 400 self:setSequence ("cowWalking") self:play() else self.y = self.y - 1.1 end end local function cowCollision (event) if event.phase == "began" then cow:setSequence ("cowBeaming") cow:play() end end cow:addEventListener ("collision",cowCollision) cow.enterFrame = cowMovement Runtime:addEventListener ("enterFrame",cow)