Trail with same distance

Hi,
I just started developing with Corona and I’m playing around with the Pool sample. I wanted to add a trail for the ball. I wanted to show the trail at same distance. I used the code below and when I look at the terminal for the distance, I have:

26.381780244754
23.276529923797
20.357230967924
19.16005247002
18.033290996604
16.972780578566
15.974674244755
15.035195993872
18.680639743354
16.897055342822
16.441087332779
16.824556587451
16.528801885102
15.665359955877
15.654783493663
15.497504230838
15.112433524753
15.031581187523
15.020930423823

Maybe someone can give a different solution? Thx

[code]
– Code located at CueShot even at ENDED phase

– START TRAILING DOTS BLOCK
local i

– First, delete previous trail
for i = trailGroup.numChildren,1,-1 do
local child = trailGroup[i]
child.parent:remove( child )
child = nil
end

local prevLocX = 0
local prevLocY = 0
local startDotCreation = function()
local createDot = function()
local dX = math.abs(prevLocX - t.x )
local dY = math.abs(prevLocY - t.y)
local distance = math.sqrt((dX*dX)+(dY*dY))
if (distance > 15) then
print( distance )

trailDot = display.newCircle( view, t.x, t.y, 3 )
trailDot:setFillColor( 255, 255, 255, 255 )
trailDot.alpha = 0.3
trailDot:toBack()
trailGroup:insert( trailDot )

prevLocX = t.x
prevLocY = t.y

end
end

dotTimer = timer.performWithDelay(5, createDot, 250 )
end
startDotCreation()
– END TRAILING DOTS BLOCK

[/code] [import]uid: 161653 topic_id: 30879 reply_id: 330879[/import]

I tried with performWithDelay(1,… and had similar result. Somehow I can understand the problem as it have to do with the physics engine and movement of the object, but I was expecting the timer to be faster and be able to catch the position when the distance is slightly after 15.
Thx for any help and suggestions. [import]uid: 161653 topic_id: 30879 reply_id: 123504[/import]

For an accurate trail you will want to use an enterFrame event listener. Use this to update the position of the trail images.

Timers are not guaranteed to fire at exactly the time you specify (in any language, on any platform) because of the code which is executing when the time to fire passes. Besides, at 250 millisecond intervals, you’re getting significantly less timer events fired than you are frames rendered. [import]uid: 8271 topic_id: 30879 reply_id: 123514[/import]

Good point thx. As mentioned, just started with Corona SKD :slight_smile: Will try to find more information about how to implement this. Cheers [import]uid: 161653 topic_id: 30879 reply_id: 123566[/import]

I tried with performWithDelay(1,… and had similar result. Somehow I can understand the problem as it have to do with the physics engine and movement of the object, but I was expecting the timer to be faster and be able to catch the position when the distance is slightly after 15.
Thx for any help and suggestions. [import]uid: 161653 topic_id: 30879 reply_id: 123504[/import]

For an accurate trail you will want to use an enterFrame event listener. Use this to update the position of the trail images.

Timers are not guaranteed to fire at exactly the time you specify (in any language, on any platform) because of the code which is executing when the time to fire passes. Besides, at 250 millisecond intervals, you’re getting significantly less timer events fired than you are frames rendered. [import]uid: 8271 topic_id: 30879 reply_id: 123514[/import]

Good point thx. As mentioned, just started with Corona SKD :slight_smile: Will try to find more information about how to implement this. Cheers [import]uid: 161653 topic_id: 30879 reply_id: 123566[/import]