Ok,
I have my drag event so when I drag my finger across a physics enabled area left and right a character will move left and right. I have now replaced the static character with a sprite animation. He only “runs” right because that is all it is showing even though the code has phycially moving left. I know this is because I don’t have it calling the sequence of him running left and only right.
In short how can I tell which direction the finger is swiping so I can call the appropriate sprite sequence?
swipe left load the run left, swipe right load the run right…
Matt
[code]
local grass = display.newImage(“grass.png”)
grass.x = 160; grass.y = 440
physics.addBody( grass, “static”)
sheetData = {width=96, height=96,numFrames=24,sheetContentWidth=512, sheetContentHeight=512,loopCount=1}
sprites = graphics.newImageSheet(“coinsprite.png”,sheetData)
sequenceData =
{
{name=“runright”,frames={9,10,11,12,13,14,15,16}},
{name=“runleft”,frames={17,18,19,20,21,22,23,24}},
{name=“dieright”,frames={6,7,8}},
{name=“dieleft”,frames={3,4,5}},
}
adventurer = display.newSprite(sprites,sequenceData)
adventurer.x = screenW/2; adventurer.y = screenH - 105
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
adventurer.isFocus = true
adventurer.x0 = event.x - adventurer.x
elseif adventurer.isFocus then
if “moved” == event.phase then
adventurer.x = event.x - adventurer.x0
adventurer:setSequence(“runright”)
adventurer:play()
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
adventurer.isFocus = false
end
end
return true
end
grass:addEventListener(“touch”, startDrag)
[/code] [import]uid: 18783 topic_id: 35535 reply_id: 335535[/import]