Sprite Animation With Drag Event

I have tried this topic before and got pretty far with it.

I have a sprite sheet.  Basically a little guy that runs left or right or stands still looking at either direction.

I am trying to avoid using a left and right button.  My character will only be able to run left or right (not up or down etc).

I have a drag event setup and it grabs his location and it even plays a sequence based on direction of the drag.  Problem is as follows.  It acts more like a swipe and release.  If the user simply drags and holds any area on the screen the character physically moves but is sprite animation for playing (running that direction) doesn’t kick in til the finger is almost lifted or is lifted (even though this is in the “moved” phase and not the “ended” phase.

Is it possible for someone to drag the screen back and forth and have the sprite animation play appropriately based on direction even if the person is not lifting their finger?  If I swipe (drag and lift if you will) the character moves and plays the sprite pretty ok.

I am about to call it not doable and just put buttons on the screen  :)

sheetData = {width=96, height=96,numFrames=24,sheetContentWidth=512, sheetContentHeight=512} sprites = graphics.newImageSheet("coinsprite.png",sheetData) sequenceData = { {name="runright",frames={7,9,10,11,12,13,14,15,16,7},loopCount=1}, {name="runleft",frames={8,17,18,19,20,21,22,23,24,8},loopCount=1}, {name="dieright",frames={6,5,2},time=700,loopCount=1}, {name="dieleft",frames={4,3,1},time=700,loopCount=1}, } adventurer = display.newSprite(sprites,sequenceData) adventurer.x = screenW/2; adventurer.y = screenH - 110 adventurer.myName = "adventureman" local adventurerShape = {-18,-18,18,-18,18,18,-18,18} physics.addBody(adventurer, "static",{isSensor=true, shape=adventurerShape}) adventurer.x = math.random(10,screenW-10) -- drag event local function startDrag( event ) if "began" == event.phase then display.getCurrentStage():setFocus(event.target) adventurer.isFocus = true adventurer.x0 = event.x - adventurer.x elseif adventurer.isFocus then if "moved" == event.phase then adventurer.x = event.x - adventurer.x0 if event.xStart \< adventurer.x then adventurer.x = event.x - adventurer.x0 adventurer:setSequence("runright") adventurer:play() end if event.xStart \> adventurer.x then adventurer.x = event.x - adventurer.x0 adventurer:setSequence("runleft") adventurer:play() end if adventurer.x \>= screenW then adventurer.x = screenW - 20 end if adventurer.x \< 0 then adventurer.x = 0 + 20 end elseif "ended" == phase or "cancelled" == phase then display.getCurrentStage():setFocus(nil) adventurer.isFocus = false adventurer:pause() end end return true end Runtime:addEventListener("touch", startDrag)

You may have to change your method of implementation. If you get a moved phase, set a flag that a swipe is in progress, so begin the animation to loop and capture last direction. Have a background timer loop to check the flag and continue direction movement. If you get an ended or cancelled phase, set the swipe flag to false and stop animation. Timer loop will see that the flag is false and movement will stop.

You may have to change your method of implementation. If you get a moved phase, set a flag that a swipe is in progress, so begin the animation to loop and capture last direction. Have a background timer loop to check the flag and continue direction movement. If you get an ended or cancelled phase, set the swipe flag to false and stop animation. Timer loop will see that the flag is false and movement will stop.