@lano78 woh that was toooo much… I am just doing my part to help fellow forum members and am also learning a lot doing that. 
[import]uid: 71210 topic_id: 13139 reply_id: 49466[/import]
@renvis@technowand: haha, and I’m sure I can speak for the rest of the forums when I say that we appreciate (and are somewhat in awe of) the help you provide! I’d like to give back in some way, so I just bought your EmoteMatch game on iTunes:)
That said, I hope I’m not overstepping my boundaries by adding one last comment/request. I have adjusted the rough code you provided so it now works as intended. Only it works almost TOO well, meaning it’s so sensitive that the “object has stopped moving” trigger goes off even when the object is moving slowly (the system reads slow movement as a rapid series of stops and starts, I believe). As an example, moving the object in rapid circles will not trigger the print(“object has stopped moving”) command, but once you start moving it in slow circles, the trigger goes off in rapid fire. Is there a way to make it not so sensitive, so the trigger goes off only when the object has come to a dead stop? Please don’t feel like you need to respond, as I realize I’ve received a lot of help from you already!
Steven
--to store previous position of x and y local prevx = 0local prevy = 0 local circle = display.newCircle(250, 250, 50)-- text to display directionlocal directionTXT = display.newText("direction: ",50,50,nil,25) local flag = 0local moved = 0local function onTouch( event ) local t = event.target local phase = event.phase if "began" == phase then -- Make target the top-most object local parent = t.parent parent:insert( t ) display.getCurrentStage():setFocus( t ) t.isFocus = true -- Store initial position t.x0 = event.x - t.x t.y0 = event.y - t.y prevx = event.x prevy = event.y elseif t.isFocus then if "moved" == phase then flag = 1 t.x = event.x - t.x0 t.y = event.y - t.y0 local dx = prevx - event.x local dy = prevy - event.y local distance = dx * dx + dy * dy if distance>400 then local angle = math.atan2(dy,dx) * 57.2957795 if angle>=22*-1 and angle<23 then string_dir="Left" elseif angle>=23 and angle<68 then string_dir="Up Left" elseif angle>=68 and angle<113 then string_dir="Up" elseif angle>=113 and angle<158 then string_dir="Up Right" elseif angle>=135 or angle<157*-1 then string_dir="Right" elseif angle>=157*-1 and angle<112*-1 then string_dir="Down Right" elseif angle>=112*-1 and angle<67*-1 then string_dir="Down"; elseif angle>=67*-1 and angle<22*-1 then string_dir="Down Left" end prevx=event.x prevy=event.y directionTXT.text = "Direction : "..string_dir moved = moved + 1 end else if "ended" == phase then flag = 0 end end end return trueend local function movementTracker(event) if flag == 0 then return true end if moved == 0 then print("not moving and last movement was towards "..string_dir) flag = 0 end moved = 0end circle:addEventListener("touch", onTouch)Runtime:addEventListener("enterFrame", movementTracker)[/code] [import]uid: 79394 topic_id: 13139 reply_id: 50040[/import]
hi edaabs,
thank you for the nice words and for the purchase 
I also noted the problem that you mentioned but din;t get time to work a fix on that as I was busy updating our Corona book (the one we use for training) with all the newly added features.
now as you have asked for I think I should find a fix to make the code work the way it is expected. the current code will be fine if we are just printing the position and last movement but when we put that into playing a sprite or movieclip it will look awkward.
I hope the below fix will make it bit better. I changed the enterframe event and added a timer to track moment. and also I added a variable counttracker to track timer ticks without any movement you can set the timer delay and counttracker to tweak the behaviour.
[lua]–to store previous position of x and y
local prevx = 0
local prevy = 0
local circle = display.newCircle(250, 250, 50)
– text to display direction
local directionTXT = display.newText("direction: ",50,50,nil,25)
local flag = 0
local moved = 0
local prevmoved = 0
local counttracker = 0
local string_dir =’’
local function onTouch( event )
local t = event.target
local phase = event.phase
if “began” == phase then
– Make target the top-most object
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
prevx = event.x
prevy = event.y
elseif t.isFocus then
if “moved” == phase then
flag = 1
t.x = event.x - t.x0
t.y = event.y - t.y0
local dx = prevx - event.x
local dy = prevy - event.y
local distance = dx * dx + dy * dy
if distance>400 then
local angle = math.atan2(dy,dx) * 57.2957795
if angle>=22*-1 and angle<23 then
string_dir=“Left”
elseif angle>=23 and angle<68 then
string_dir=“Up Left”
elseif angle>=68 and angle<113 then
string_dir=“Up”
elseif angle>=113 and angle<158 then
string_dir=“Up Right”
elseif angle>=135 or angle<157*-1 then
string_dir=“Right”
elseif angle>=157*-1 and angle<112*-1 then
string_dir=“Down Right”
elseif angle>=112*-1 and angle<67*-1 then
string_dir=“Down”;
elseif angle>=67*-1 and angle<22*-1 then
string_dir=“Down Left”
end
prevx=event.x
prevy=event.y
directionTXT.text = "Direction : "…string_dir
moved = moved + 1
counttracker = 0
end
else if “ended” == phase then
flag = 0
moved = 0
end
end
end
return true
end
local function movementTracker(event)
if flag == 0 then return true end
if moved == prevmoved then
if counttracker == 1 then
print("not moving and last movement was towards "…string_dir)
flag = 0
end
end
counttracker = counttracker + 1
prevmoved = moved
end
circle:addEventListener(“touch”, onTouch)
timer.performWithDelay(400, movementTracker,0)[/lua] [import]uid: 71210 topic_id: 13139 reply_id: 50065[/import]
Hi Technowand-Renjith,
Your code worked like a charm. Some of the rapid fire stopping and starting problems returned when I dialed down the delay (I had to set it at 1 millisecond for responsiveness), but a simple shifting of the flag from line 31 down to just below line 38 (the “if distance>400” statement) got rid of this problem, and now my code works great! Thanks to your help, I was able to succesfully craft the player movement and animation for my game and have learned a lot about coding. I cannot say enough about how much I appreciate your help, you make me wish I owned a huge company so I could hire you and pay you millions:). I’ve just purchased your Corona Development E-book from your website and look forward to learning more. You’ve made my first experience with Corona very inspiring.
Cheers,
Steven [import]uid: 79394 topic_id: 13139 reply_id: 50146[/import]
Thanks for those nice words Steven. Good to know that the code worked. 
also thank you so much for the purchase. Am working on an update for that book with all the latest additions to the SDK. Hope to release it by next week. will send you the updated version once it is ready.
by the way don’t forget your words… if your game become the next Angry Bird or Cut the rope do hire me…
[import]uid: 71210 topic_id: 13139 reply_id: 50175[/import]
Deal:) [import]uid: 79394 topic_id: 13139 reply_id: 50307[/import]