Hi guys.
in my game I have a ball table. I wish that by moving a ball the others would follow it with a little delay.
I’ve tried various solutions but I think the best idea is something with math.
small basic code:
local balls = {} for i = 1, 7 do local ball = display.newCircle( 0, 250, 14) ball.x = 40\*i ball:setFillColor( math.random(), math.random(), math.random() ) function ball:touch(event) local phase = event.phase if( phase == "began" ) then self.isFocus = true display.currentStage:setFocus( self ) self.x0 = self.x --self.y0 = self.y print("began") elseif( self.isFocus ) then if(phase == "moved")then local dx = event.x - event.xStart --local dy = event.y - event.yStart self.x = self.x0 + dx --self.y = self.y0 + dy event.dx = dx --event.dy = dy print("move") elseif(phase == "ended" or phase == "cancelled" ) then self.isFocus = false display.currentStage:setFocus( self ) print("ended") end end return true end ball:addEventListener( "touch" ) balls[i] = ball end
Looking on the internet I found a famous game. I would like to be able to achieve an equal movement effect.
https://www.youtube.com/watch?v=ifuOYkIqH6k
(at time 1:30-1:38 if necessary, look in slow motion)
As you can see the objects do not follow the main at the same speed but with a slight delay that gives a nice effect