Is there a way for an object to leave/draw a trail when it is moved?

I am making this game: https://www.youtube.com/watch?v=OHB6OkwS6es&index=2&list=PL0M8uLpJgrPqjMyqG34xE9NZNa7nZgLxT

I want to make the ball leave/draw a trail when it is moved and if possible (though it probably would be a lot harder to do) I would want the trail to have a chalk look. Is this possible? How would I do it? Are there any tutorials on this?

its quite simple but you could try something like this

  local trailprops = {x= 0, y = 0,r = 10} local ball = display.newCircle( 0, 0, 10 ) transition.to( ball, {time = 5000, x = 160,y = 240} ) local function redraw ()     local Trail = display.newCircle( ball.x + trailprops.x, ball.y + trailprops.y, trailprops.r)     Trail:setFillColor( 0,0.7,1 )     transition.to( Trail, {time = 500, alpha = 0, onComplete = function ()         display.remove( Trail )     end} )     ball:toFront( )     print("!") end Runtime:addEventListener( "enterFrame", redraw )  

Thanks that works, except I already made the ball, so making another would cause problems (just in case anyone else wants the same thing). Also, if you want to have the trail to be below your ball (or whatever other object), you need to “group:insert(Trail)”  and then call “ball:toFront()”. Thanks so much for your help!

But is there anyway to make the line a little smoother? I hate how the fading reveal the overlapping circles. I find it kind ugly

hmm i guess increaing the fps to 60 would but i cant think of much else

It is 60 fps.

Hi!  I liked this question, so I posted a quick article in reply here:

http://roaminggamer.com/2014/06/19/easy-ball-trails-corona-sdk/

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

Cheers,

Ed

Is there a way to make the trails fade behind the ball after so long?

Thats what 86lemonade68’s code did. The

transition.to( Trail, {time = 500, alpha = 0, onComplete = function ()
        display.remove( Trail )
    end} )

Makes the trail fade out. However, its pretty easy to see that the trail is just circles when it does that and so it looks a bit ugly. That is why I asked if there was a way to make the trail look smoother.

I’m an idiot. Sorry was watching the video right above my post. Didn’t see that part.

Yeah, the effect I was going for is a very thin line and I’ve been tweaking the code a lot with no luck.

Its easy to miss something, dont take it so hard. Anyway, if you are using 86lemonade86’s code, then change r to be smaller

@All,

I updated the code frommy article, adding balls that fade after a while, and trail fading.  I also added two additional drawTrail() examples (drawTrail2(), drawTrail3()).

You can get the code here: https://github.com/roaminggamer/RG_FreeStuff/tree/master/ballTrail

I got his code fully working. Trying to implement a solid line behind a ball. Haven’t had any luck yet! Have you?

No, not really. I changed

transition.to( Trail, {time = 500, alpha = 0, onComplete = function ()         display.remove( Trail )     end} )

to

transition.to( Trail, {time = 130, alpha = 0, onComplete = function()             display.remove( Trail )         end} )

pretty much I changed the time to be shorter. You get a shorter trail, but while testing it, it looks pretty good. Make sure your game is set at 60fps.

Still, I wish there was a better way, especially for long trails.

If you want a solid line that doesn’t fade then I think roaminggamer’s code might work or you can just not have the transition that removes the trail (the code in this post) in 86lemonade68’s code.

I’m using his code in this game: http://www.indiedb.com/games/chalkboard-bounce and as I stated before. It looks decent, but definitely not state-of-the-art or awesome.

You can also create a single line (newLine) object and append points to it over time.  You can’t fade this out, but you’ll get a contiguous line.

its quite simple but you could try something like this

  local trailprops = {x= 0, y = 0,r = 10} local ball = display.newCircle( 0, 0, 10 ) transition.to( ball, {time = 5000, x = 160,y = 240} ) local function redraw ()     local Trail = display.newCircle( ball.x + trailprops.x, ball.y + trailprops.y, trailprops.r)     Trail:setFillColor( 0,0.7,1 )     transition.to( Trail, {time = 500, alpha = 0, onComplete = function ()         display.remove( Trail )     end} )     ball:toFront( )     print("!") end Runtime:addEventListener( "enterFrame", redraw )  

Thanks that works, except I already made the ball, so making another would cause problems (just in case anyone else wants the same thing). Also, if you want to have the trail to be below your ball (or whatever other object), you need to “group:insert(Trail)”  and then call “ball:toFront()”. Thanks so much for your help!

But is there anyway to make the line a little smoother? I hate how the fading reveal the overlapping circles. I find it kind ugly

hmm i guess increaing the fps to 60 would but i cant think of much else

It is 60 fps.