try this
[lua]local physics = require(“physics”)
physics.start()
physics.setGravity(0, 0)
–physics.setDrawMode(“hybrid”)
physics.setDrawMode(“normal”)
–forward declaration for functions
–now the order of function doesn’t matter
local onTouch,movementTracker,wrap,cleanUp,moveCamera,flag4reset,onPlayerCollision,scooterSpawn
local background=display.newImage(“Street (first version).png”)
background:setReferencePoint(display.TopLeftReferencePoint)
background.x=0
background.y=0
local background2=display.newImage(“Street (first version).png”)
background2:setReferencePoint(display.TopLeftReferencePoint)
background2.x=0
background2.y=-1024
local background3=display.newImage(“Street (first version).png”)
background3:setReferencePoint(display.TopLeftReferencePoint)
background3.x=0
background3.y=-1024
local loqsprite = require(‘loq_sprite’)
local playerFactory = loqsprite.newFactory(‘playerSheet’)
local spriteFactory = loqsprite.newFactory(‘sheet’)
local angelFactory = loqsprite.newFactory(‘angelSheet’)
local player = playerFactory:newSpriteGroup()
atrace(xinspect(player:getSpriteNames()))
local prevx = 0
local prevy = 0
local dragDirection
local string_dir = ‘’
local flag
local flag2
local flag3
local flag4
local moved = 0
local counttracker = 0
player.x = 385
player.y = 970
player:addPhysics(physics,‘kinematic’,{})
physics.addBody(player,“kinematic”)
player:play(‘Player static back view’)
– text to display direction
local directionTXT = display.newText("Direction: ",130,25,nil,25)
directionTXT:setTextColor( 255,0,0 )
–Player movement function
function onTouch( event )
local player = event.target
local phase = event.phase
if “began” == phase then
– Make target the top-most object
local parent = player.parent
parent:insert( player )
display.getCurrentStage():setFocus( player )
– Spurious events can be sent to the target, e.g. the user presses
– elsewhere on the screen and then moves the finger over the target.
– To prevent this, we add this flag. Only when it’s true will “move”
– events be sent to the target.
player.isFocus = true
– Store initial position
player.x0 = event.x - player.x
player.y0 = event.y - player.y
prevx = event.x
prevy = event.y
elseif player.isFocus then
if “moved” == phase then
– Make object move (we subtract t.x0,t.y0 so that moves are
– relative to initial grab point, rather than object “snapping”).
player.x = event.x - player.x0
player.y = event.y - player.y0
local sqrt = math.sqrt
local dx = prevx - event.x
local dy = prevy - event.y
local distance = sqrt(dx * dx + dy * dy);
if distance>10 then
flag=“off”
local angle = math.atan2(dy,dx) * 57.2957795
if angle>=45*-1 and angle<=45 then
string_dir=“Left”
if dragDirection ~= “left” then
player:play(‘Player run side view left’)
dragDirection = “left”
end
elseif angle>45 and angle<135 then
string_dir=“Up”
if dragDirection ~= “up” then
player:play(‘Player run back view’)
dragDirection = “up”
end
elseif angle>135*-1 and angle<45*-1 then
string_dir=“Down”
if dragDirection ~= “down” then
player:play(‘Player run front view’)
dragDirection = “down”
end
elseif angle>=135 or angle<=135*-1 then
string_dir=“Right”
if dragDirection ~= “right” then
player:play(‘Player run side view right’)
dragDirection = “right”
end
end
prevx=event.x
prevy=event.y
directionTXT.text ="Direction : "…string_dir
moved = moved + 1
counttracker = 0
end
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
if string_dir == “Left” then
player:play(‘Player static left side view’)
elseif string_dir == “Up” then
player:play(‘Player static back view’)
elseif string_dir == “Down” then
player:play(‘Player static front view’)
elseif string_dir == “Right” then
player:play(‘Player static right side view’)
end
dragDirection = “stopped”
flag = “on”
end
– Important to return true. This tells the system that the event
– should not be propagated to listeners of any objects underneath.
return true
end
end
function movementTracker(event)
if moved == 0 then
if flag ~= “on” then
if counttracker == 3 then
print("not moving and last movement was towards "…string_dir)
if string_dir == “Left” then
player:play(‘Player static left side view’)
elseif string_dir == “Up” then
player:play(‘Player static back view’)
elseif string_dir == “Down” then
player:play(‘Player static front view’)
elseif string_dir == “Right” then
player:play(‘Player static right side view’)
end
dragDirection = “stopped”
flag = “on”
end
end
end
counttracker = counttracker + 1
moved = 0
end
function wrap (event)
if player.x < 25 then
player.x = 25
end
if player.x > 743 then
player.x = 743
end
if player.y < 50 then
player.y = 50
–to move the scooter group
moveCamera()
–you should remove the collisiion listener when moving else it may collide with object and your player will become Angel 
player:removeEventListener( “collision”, onPlayerCollision )
–1st transition of background and player down one screen’s length
if flag2~=“on” then
flag = “on”
timer.performWithDelay(1000,function(event) player:addEventListener(“touch”,onTouch) end, 1)
function playerStopFunction()
player:play(‘Player static back view’)
end
timer.performWithDelay(1000,playerStopFunction,1)
player:removeEventListener( “touch”, onTouch )
display.getCurrentStage():setFocus( nil )
player.isFocus = false
player:play(‘Player run back view’)
transition.to(player, {time = 1000, delay = 0, y = player.y + 920})
transition.to(background, {time = 1000, delay = 0, y = background.y + 1024})
transition.to(background2, {time = 1000, delay = 0, y = background2.y + 1024})
flag2=“on”
–2nd transition of background and player down one more screen’s length
elseif flag3~=“on” then
flag = “on”
timer.performWithDelay(1000,function(event) player:addEventListener(“touch”,onTouch) end, 1)
function playerStopFunction()
player:play(‘Player static back view’)
end
timer.performWithDelay(1000,playerStopFunction,1)
player:removeEventListener( “touch”, onTouch )
display.getCurrentStage():setFocus( nil )
player.isFocus = false
player:play(‘Player run back view’)
transition.to(player, {time = 1000, delay = 0, y = player.y + 920})
transition.to(background2, {time = 1000, delay = 0, y = background2.y + 1024})
transition.to(background3, {time = 1000, delay = 0, y = background3.y + 1024})
flag3=“on”
end
end
if player.y > 1010 then
player.y = 1010
end
end
–forward declaration of the table, so it is visible.
local spawnedGroup = display.newGroup()
local transitions = {}
local timers = {}
function scooterSpawn (event)
local scooter = spriteFactory:newSpriteGroup(‘Scooter 1 moving right’)
scooter:addPhysics(physics,‘dynamic’,{})
scooter.x = -100
scooter.y = math.random(120,924)
physics.addBody(scooter,“dynamic”,{isSensor = true})
scooter.isSensor = true
transitions[#transitions + 1] = transition.to(scooter, {time = math.random(1400,1500), delay = 0, x = scooter.x + 968, onComplete=function() scooter :removeSelf() end})
spawnedGroup:insert(scooter)
end
cleanUp = function()
–cancel and nil all the transitions
for i=1,#transitions do
if transitions[i] then
transition.cancel(transitions[i])
transitions[i] = nil
end
end
–cancel and nil all the timers
for i=1,#timers do
if timers[i] then
timer.cancel(timers[i])
timers[i] = nil
end
end
display.remove(spawnedGroup)
end
moveCamera = function()
transitions[#transition + 1] = transition.to(spawnedGroup, {time = 1000, y = spawnedGroup.y + 1200, onComplete = cleanUp})
end
timers[#timers + 1] = timer.performWithDelay(math.random(20,35),scooterSpawn,0)
function flag4reset(event)
flag4=“off”
end
–Collision function
function onPlayerCollision()
if flag4~=“on” then
player.isVisible = false
local angel = angelFactory:newSpriteGroup(‘Player Angel copy 2’)
angel.x = player.x
angel.y = player.y
transition.to(angel, {time = 1000, delay = 0, y = player.y - 920, onComplete=function() angel :removeSelf() end})
timer.performWithDelay(1000,function() player.isVisible = true end,1)
timer.performWithDelay(1000,function() player.y = 970 end,1)
media.playEventSound( “Punch.wav” )
print(“collided with square”)
flag4=“on”
timer.performWithDelay(1000,flag4reset,1)
end
end
player:addEventListener(“collision”,onPlayerCollision)
Runtime:addEventListener(“enterFrame”, wrap)
player:addEventListener( “touch”, onTouch )
timer.performWithDelay(1, movementTracker,0)[/lua] [import]uid: 71210 topic_id: 15294 reply_id: 56611[/import]