You have plenty of ways to approach this. Perhaps the easiest is via transitions and easing, something along the lines of this:
local shakeDone = true local shakeDistance = 50 local shakeTime = 50 local object = display.newRect( 240, 160, 180, 60 ) local function shakeReset() shakeDone = true end local function shakeEnd() transition.to( object, {time=shakeTime, x=object.x-shakeDistance, transition=easing.continuousLoop, onComplete=shakeReset}) end local function shake( event ) if event.phase == "ended" then if shakeDone then shakeDone = false transition.to( object, {time=shakeTime, x=object.x+shakeDistance, transition=easing.continuousLoop, onComplete=shakeEnd}) end end end local sensor = display.newRect( 240, 160, 480, 360 ) sensor.isVisible = false sensor.isHitTestable = true sensor:addEventListener( "touch", shake )