Ah I see … well it’s all about the tweaking - also they may use other formulas to apply the changes (like interpolating the rotation instead of adding vectors etc.) - it’s only meant as a simple starting point for the general idea.
Here’s a slightly tweaked version, also added a small startup delay to give it a try on a device and a simple trail (obviously for a real implementation you’d have to use meshes).
I can easily move in a 8 or similar symbols with this version, but of course it’s still not 100% identical - again, just meant to give you a starting point.
[lua]
local vehicle = display.newRect( display.contentWidth/2, display.contentHeight/2, 10, 10 )
local speed = 120
local dt = 1/60
local appear = transition.from( vehicle, { delay = 1000, time = 800, transition = easing.outElastic,
alpha = 0, xScale = 0.01, yScale = 0.01,
onComplete = function() Runtime:addEventListener( “enterFrame”, update) end })
local touch = { x = 0, y = 0 }
vehicle.vel = { x = speed, y = 0 }
local FRAMES_PER_TRAIL = 4
local trail = { nextTrail = FRAMES_PER_TRAIL }
print( trail.nextTrail )
function update( event )
local vel = vehicle.vel
vehicle.x = vehicle.x + vel.x * dt
vehicle.y = vehicle.y + vel.y * dt
vel.x = vel.x + touch.x
vel.y = vel.y + touch.y
local velLen = math.sqrt( vel.x*vel.x + vel.y*vel.y )
vel.x = vel.x / velLen * speed
vel.y = vel.y / velLen * speed
touch.x = touch.x * 0.5
touch.y = touch.y * 0.5
local RAD2DEG = 180 / math.pi
local angle = (math.atan2( vel.y, vel.x ) * RAD2DEG)
vehicle.rotation = angle
trail.nextTrail = trail.nextTrail - 1
if trail.nextTrail <= 0 then
trail.nextTrail = FRAMES_PER_TRAIL
local r = display.newRect( vehicle.x, vehicle.y, 10, 10 )
r.rotation = vehicle.rotation
end
end
function handleTouch( event )
local phase = event.phase
if phase == “began” then
else
touch.x = touch.x + (event.x - touch.lastX) * 3
touch.y = touch.y + (event.y - touch.lastY) * 3
end
touch.lastX = event.x
touch.lastY = event.y
end
Runtime:addEventListener( “touch”, handleTouch )
[/lua]