Hello
I used a tween to move a movieclip. The tween is generated on touch.
Everything works great as long as I am gentle, and don't click/touch too fast. When I go fast (like I expect a player to be), I get some glitches: most often it is a teleport instead of a smooth animation.
Here is my code:
local function followTween(ship, event)
local xship, yship = ship:getPosition()
print ("Ship: ", xship," x ", yship)
--print(ship:getPosition())
print ("touch!")
local x = event.touch.x
local y = event.touch.y
print (x," x ", y)
-- constant speed
local dist = math.sqrt((xship-x)^2+(yship-y)^2)
local speed = 400
local duration = dist/speed
-- gtween props
local animate ={}
animate.x = x
animate.y = y
local properties = {}
properties.delay = 0
properties.ease = easing.linear
-- gtween call
local tween = GTween.new(ship, duration, animate, properties)
end |
This function is called via
mapb:addEventListener(Event.TOUCHES_END, followTween, rmship) |
I am a beginner so I guess my code might be lacking some useful subtleties. What should I do?
Comments
Likes: MoKaLux