Sprite sequence after swipe event

Hi everyone!
I’m building a simple game in Corona (infinite scrolling with obstacles).
I have a sprite object with 3 sequences: walking, jumping and crouching.

This is the code I use to jump or crouch depending on the swipe direction (up and down):

---peste is the sprite object
local function swipeEvent (event)
	if (event.phase == "ended" ) then
		if event.y > event.yStart then
			print ("Crouch")
			peste:setSequence("crouch")
			peste:play()

		elseif event.y < event.yStart then
			print ("Jump")
			peste:applyLinearImpulse(0,-15.5,peste.x,peste.y)
			peste:setSequence("jump")
			peste:play()
		end	
	end	
end
Runtime:addEventListener("touch", swipeEvent) 

I need a way to let it start walking again after the event.
Can you help me?

ps. I’m entry level and not so good in coding :confused:

1 Like

Maybe something like that

if event.y > event.yStart then
	print ("Crouch")
	peste:setSequence("crouch")
	peste:play()
	peste:addEventListener( "sprite", afterCrouch)
...
...

local function afterCrouch(event)
	if (event.phase == "ended")
		print ("Crouch Ended")
		peste:setSequence("walking")
		peste:play()
	end
end

I’m using this kind of code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.