Hi,
Look at this Video:
http://www.youtube.com/watch?v=Ph2XHMmW29s
At the beginning is my game. The letters are small but the issue I’m having is being caused with big letters as well.
When I drag a letter to fast the touch event (I think) is being cancelled and the app just leaves the letter there. If I do end the touch event controllable i.e. the finger is still on the letter, I lift it and event.phase == “ended” is being executed it does what I expect however it looks like if the finger is moving to fast the the event doesn’t “end”.
However, that’s not really my problem. The problem is, as you can see in the video in the game “Words in a Pic” that if I drag a letter in that app it follows the fingers movement even if the finger is no longer is on the letter (i.e. i drag the finger really fast) and that’s what I want.
The problem, I think, is that I create local function for each letter but it might be better to have a Runtime touch event?
I also have another event, a local collision event that is triggered when a letter is colliding with an “emptybox”( the blue one,
Here is the local “drag” event:
t:addEventListener("touch", function(event) if touchOnGoing == 0 or touchOnGoing == t.i then touchOnGoing = t.i if event.phase == "began" then t.markX = t.x -- store x location of object t.markY = t.y -- store y location of object t:toFront() local o = t.occupying print("o: "..o) if o ~= 0 then t.occupying = 0 emptyBoxes[o].occupiedBy = 0 emptyBoxes[o].letter = "0" end print("occupying: "..t.occupying) if o ~= 0 then print("occupiedBy "..emptyBoxes[o].occupiedBy) print("letter: "..emptyBoxes[o].letter) end elseif event.phase == "moved" then if t.markX ~= nil then local x = (event.x - event.xStart) + t.markX local y = (event.y - event.yStart) + t.markY t.x, t.y = x, y -- move object based on calculations above end -- The finger is being lift elseif event.phase == "ended" then if overBox \> 0 and emptyBoxes[overBox].occupiedBy == 0 then transition.to(t, {time = 150, x = emptyBoxes[overBox].orgX, y = emptyBoxes[overBox].orgY}) emptyBoxes[overBox].occupiedBy = overBox emptyBoxes[overBox].letter = t.letter t.occupying = overBox print("IF --- ") print("occupying: "..t.occupying) print("occupiedBy "..emptyBoxes[overBox].occupiedBy) print("letter: "..emptyBoxes[overBox].letter) elseif overBox == 0 or emptyBoxes[overBox].occupiedBy ~= 0 then transition.to(t, {time = 150, x = t.orgX, y = t.orgY}) end -- Atleast in the simulator when the mouse is released the ended activity starts and sets touchOnGoing = 0 -- and another touch event can starts which means that if another letter is beneath that letter touchOnGoing will be set -- to that value and if they are in a box both will be return to their original position local function setTouchOnGoing(event) touchOnGoing = 0 end timer.performWithDelay(50, setTouchOnGoing) end end end)
I feel that I should try to use Runtime events instead to facilitate the code and to be able to use a little bit smoother dragging but I’m not sure.
Can someone give some input here on how to make my letters drag more smooth?
Best regards,
Tomas