How to make snake move smoothly ?

Hi, I am making a classic snake and I want to ask how to make snake move smoothly ?

local body = {} local head = display.newRect(80,200,20,20) body[1] = display.newRect(80,220,20,20) body[2] = display.newRect(80,240,20,20) body[3] = display.newRect(80,260,20,20) dir = 'up' function update() local lastX = head.x local lastY = head.y local xPos = {} local yPos = {} if(dir == 'up') then transition.to(head,{time=500,y=head.y-20,onComplete=function(self) update() end}) --head.y = head.y - 20 elseif(dir == 'left') then transition.to(head,{time=500,x=head.x-20,onComplete=function(self) update() end}) --head.x = head.x - 20 elseif(dir == 'down') then transition.to(head,{time=500,y=head.y+20,onComplete=function(self) update() end}) --head.y = head.y + 20 elseif(dir == 'right') then transition.to(head,{time=500,x=head.x+20,onComplete=function(self) update() end}) --head.x = head.x + 20 end for i = 1, 3 do -- Capture parts position to move them xPos[i] = body[i].x yPos[i] = body[i].y -- Move Parts if(body[i-1] == nil) then -- body[i].x = lastX -- body[i].y = lastY transition.to(body[i],{time=500,x=lastX ,y=lastY ,onComplete=function(self) end}) else -- body[i].x = xPos[i-1] -- body[i].y = yPos[i-1] transition.to(body[i],{time=500,x=xPos[i-1] ,y= yPos[i-1] ,onComplete=function(self) end}) end end end local function changeDir() if dir == 'up' then dir = 'right' elseif dir == 'right' then dir = 'down' elseif dir == 'down' then dir = 'left' elseif dir == 'left' then dir = 'up' end end update() timer.performWithDelay(2500,changeDir,0)

This may helphttps://github.com/maxwellrocker/Snake/blob/master/main.lua

The ‘follow the leader’ example form my May 2015 Answer pack may give you some insights:

https://www.youtube.com/watch?v=1H4jATyCbew&feature=youtu.be

-- ============================================================= -- Answers to interesting Corona Forums Questions -- ============================================================= -- by Roaming Gamer, LLC. 2009-2015 (http://roaminggamer.com/) -- ============================================================= display.setStatusBar(display.HiddenStatusBar) -- Notes for this example ( not part of example ) -- local notes = { "Contrary to what the title says, this question was about making", "a series of objects follow each other in uniform way.", "", "1. Click anywhere to make objects move an follow each other." } for i = 1, #notes do local tmp = display.newText( notes[i], 50, 20 + (i-1) \* 30, native.systemFont, 22 ) tmp.anchorX = 0 end -- -- Load SSK --require "ssk.loadSSK" -- -- Localize some useful functions local newCircle = ssk.display.newCircle local newRect = ssk.display.newRect local newImageRect = ssk.display.newImageRect local easyIFC = ssk.easyIFC local mRand = math.random local angle2Vector = ssk.math2d.angle2Vector local vector2Angle = ssk.math2d.vector2Angle local scaleVec = ssk.math2d.scale local addVec = ssk.math2d.add local subVec = ssk.math2d.sub local getNormals = ssk.math2d.normals local lenVec = ssk.math2d.length local normVec = ssk.math2d.normalize -- -- Set up sphysics local physics = require("physics") physics.start() physics.setGravity(0,0) physics.setDrawMode( "hybrid" ) -- -- Set up some locals to control demo local group = display.newGroup() local moveSpeed = 400 local circleColors = { \_R\_, \_G\_, \_B\_, \_O\_, \_Y\_, \_P\_, \_C\_ } local circleRadius = {} for i = 1, #circleColors do circleRadius[i] = 30 - (i-1) \* 3 end -- -- 'enterFrame' lister that does moving work local function onEnterFrame( self ) local myNum = self.myNum local prior = self.priorCircle local vec = subVec( prior, self ) vec = normVec( vec ) vec = scaleVec( vec, 2 \* circleRadius[myNum-1] + 2 ) self.x = prior.x + vec.x self.y = prior.y + vec.y end -- -- Create background object to 'catch' touches local circles = {} local x = centerX + 100 local y = centerY for i = 1, #circleRadius do if( i == 1 ) then circles[i] = newCircle( group, x, y, { radius = circleRadius[i], fill = circleColors[i] } ) else circles[i] = newCircle( group, x, y, { radius = circleRadius[i], fill = circleColors[i], myNum = i, priorCircle = circles[i-1], enterFrame = onEnterFrame } ) end x = x - 2 \* circleRadius[i] + 2 end -- -- Touch Listener (and mover) local function onTouch( self, event ) if( event.phase == "began" ) then -- Stop any current transitions -- for i = 1, #circles do transition.cancel( circles[i] ) end -- Calc distance First circle needs to move -- local tvec = { x = event.x, y = event.y } local vec = subVec( tvec, circles[1] ) local len = lenVec( vec ) local time = 1000 \* len / moveSpeed transition.to( circles[1], { x = tvec.x, y = tvec.y, time = time }) end return true end local touchCatcher = newRect( group, centerX, centerY, { w = fullw, h = fullh, touch = onTouch, fill = \_DARKERGREY\_ } ) touchCatcher:toBack()

I am using timer.performWithDelay() to make the snake move along a grid, is there anyway to make the snake move 

smoothly like this game ?

https://www.youtube.com/watch?v=NQg3IBJYIDE

This may helphttps://github.com/maxwellrocker/Snake/blob/master/main.lua

The ‘follow the leader’ example form my May 2015 Answer pack may give you some insights:

https://www.youtube.com/watch?v=1H4jATyCbew&feature=youtu.be

-- ============================================================= -- Answers to interesting Corona Forums Questions -- ============================================================= -- by Roaming Gamer, LLC. 2009-2015 (http://roaminggamer.com/) -- ============================================================= display.setStatusBar(display.HiddenStatusBar) -- Notes for this example ( not part of example ) -- local notes = { "Contrary to what the title says, this question was about making", "a series of objects follow each other in uniform way.", "", "1. Click anywhere to make objects move an follow each other." } for i = 1, #notes do local tmp = display.newText( notes[i], 50, 20 + (i-1) \* 30, native.systemFont, 22 ) tmp.anchorX = 0 end -- -- Load SSK --require "ssk.loadSSK" -- -- Localize some useful functions local newCircle = ssk.display.newCircle local newRect = ssk.display.newRect local newImageRect = ssk.display.newImageRect local easyIFC = ssk.easyIFC local mRand = math.random local angle2Vector = ssk.math2d.angle2Vector local vector2Angle = ssk.math2d.vector2Angle local scaleVec = ssk.math2d.scale local addVec = ssk.math2d.add local subVec = ssk.math2d.sub local getNormals = ssk.math2d.normals local lenVec = ssk.math2d.length local normVec = ssk.math2d.normalize -- -- Set up sphysics local physics = require("physics") physics.start() physics.setGravity(0,0) physics.setDrawMode( "hybrid" ) -- -- Set up some locals to control demo local group = display.newGroup() local moveSpeed = 400 local circleColors = { \_R\_, \_G\_, \_B\_, \_O\_, \_Y\_, \_P\_, \_C\_ } local circleRadius = {} for i = 1, #circleColors do circleRadius[i] = 30 - (i-1) \* 3 end -- -- 'enterFrame' lister that does moving work local function onEnterFrame( self ) local myNum = self.myNum local prior = self.priorCircle local vec = subVec( prior, self ) vec = normVec( vec ) vec = scaleVec( vec, 2 \* circleRadius[myNum-1] + 2 ) self.x = prior.x + vec.x self.y = prior.y + vec.y end -- -- Create background object to 'catch' touches local circles = {} local x = centerX + 100 local y = centerY for i = 1, #circleRadius do if( i == 1 ) then circles[i] = newCircle( group, x, y, { radius = circleRadius[i], fill = circleColors[i] } ) else circles[i] = newCircle( group, x, y, { radius = circleRadius[i], fill = circleColors[i], myNum = i, priorCircle = circles[i-1], enterFrame = onEnterFrame } ) end x = x - 2 \* circleRadius[i] + 2 end -- -- Touch Listener (and mover) local function onTouch( self, event ) if( event.phase == "began" ) then -- Stop any current transitions -- for i = 1, #circles do transition.cancel( circles[i] ) end -- Calc distance First circle needs to move -- local tvec = { x = event.x, y = event.y } local vec = subVec( tvec, circles[1] ) local len = lenVec( vec ) local time = 1000 \* len / moveSpeed transition.to( circles[1], { x = tvec.x, y = tvec.y, time = time }) end return true end local touchCatcher = newRect( group, centerX, centerY, { w = fullw, h = fullh, touch = onTouch, fill = \_DARKERGREY\_ } ) touchCatcher:toBack()

I am using timer.performWithDelay() to make the snake move along a grid, is there anyway to make the snake move 

smoothly like this game ?

https://www.youtube.com/watch?v=NQg3IBJYIDE