Need help with trail effect

Is it possible to make a trail effects exactly like the one in this video with corona? If it is, can some one write a sample code how to make it? I really need it for my game so please help me. 

Here is the link:

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

Hi there,

There’s always workarounds, trickery and weird convoluted ways to achieve an approximation of an effect. But besides that, I don’t think there is a straightforward way to do this in Corona. Maybe I’m wrong, and you can always write a plugin, but I don’t think it’ll be simple for the average user.

Hi. I’ve done this (in 3D), so I know it can be done. But as Thomas says, it’s not one of those “just do this, and you’re done” sort of problems.

As is often the case, it seems, my plan of attack would be a custom effect, using display.newPolygon() to create a reasonably flexible shape to operate on. I demonstrated this on one of the Corona Geek shows a couple months back, e.g. see us looking at a polygon’s animating vertices here. There’s some development in the minutes leading up to that, of course. (Code for that sample: Wavy Text)

I built curving trails using Catmull-Rom splines, which have the advantage of passing through all their control points (versus, say, a Beziér spline where two of the points will generally be off the curve), so it’s pretty straightforward to build them and string them together, although you do have to “guess” a little about the next point coming up.

The polygon represents the most current part of the trail, which segment you update until it reaches a current length, then “freeze” and leave behind, starting a new one.

Anyhow, take a look at those first and see if you can get a feel for the material. That should be a good start.

Check out the “Simple Trails freebie” post I just did. It might set you on the way.

@ thomas6 I need to do a max(…, .01) on the xScale to have it not error on me about setting it to 0. Also it was a little unintuitive being in the corner. But the example itself is good.

@ Chris1985 I should point out that my way was meant to accommodate texturing along the trail, but for stuff like the effect, smearing particles along a path should work out decently. The spline might still be worth looking into, though, to attempt a smoother fit.

@ thomas6  Thank you for reply! I really like the “Simple Trails freebie” but i think that is not what i need. In the video that i posted, the circle only move up and down and the trail is follow it. Anyway, your sample help me to find a way to do it, maybe a stupid way :stuck_out_tongue: , but it help me a lot, thank you very much.

@ StarCrunch  Using custom shader is kind of hard for me right now, i have no coding experience and i just study Corona myself more than a month. I really appreciate your help, i will try it later.  :) 

English isn’t my first language, so please excuse any mistakes.

I don’t want to start another topic so i write another question here. My code :

local mySetting={} mySetting.soundon = true if mySetting.soundon then audio.setVolume( 1.0 ) else audio.setVolume( 0.0 ) end function volumeoff(event) if event.phase == "ended" then mySetting.soundon = false transition.to(voloff,{time=2,alpha=1}) transition.to(volon,{time=2,alpha=0}) voloff:addEventListener( "touch", volumeon ) volon:removeEventListener( "touch", volumeoff ) end end function volumeon(event) if event.phase == "ended" then mySetting.soundon = true transition.to(voloff,{time=2,alpha=0}) transition.to(volon,{time=2,alpha=1}) volon:addEventListener( "touch", volumeoff ) voloff:removeEventListener( "touch", volumeon ) end end

If i change “mySetting.soundon = false” in line 2 then my game has no sound, but it not work in function. What did i do wrong? and how can i save my sound setting?

Well, maybe you’ll look at some of those ideas later.

You actually should start a new topic in a case like this, since some people don’t care about trails and won’t bother looking here.

A couple points: time is in milliseconds. If you want seconds, you should use 2000, not 2. Also, you probably want to return true from your touch listeners, just to avoid weird problems later.

Inside your functions, you’re not calling the important audio.setVolume (). You could wrap it up a bit and do something like:

local mySetting={} local function SetSoundState (on) mySetting.soundon = on if on then audio.setVolume(1.0) else audio.setVolume(0.0) end end SetSoundState(true) -- Start on; when you have loading code, use that here... -- Then, inside volumeoff, instead of setting soundon directly: SetSoundState(false) -- And similarly inside volumeon: SetSoundState(true)

Saving: read some of these

Please start new threads if the topic is different.

Rob

I made it! Thank you all  :smiley:

Hi there,

There’s always workarounds, trickery and weird convoluted ways to achieve an approximation of an effect. But besides that, I don’t think there is a straightforward way to do this in Corona. Maybe I’m wrong, and you can always write a plugin, but I don’t think it’ll be simple for the average user.

Hi. I’ve done this (in 3D), so I know it can be done. But as Thomas says, it’s not one of those “just do this, and you’re done” sort of problems.

As is often the case, it seems, my plan of attack would be a custom effect, using display.newPolygon() to create a reasonably flexible shape to operate on. I demonstrated this on one of the Corona Geek shows a couple months back, e.g. see us looking at a polygon’s animating vertices here. There’s some development in the minutes leading up to that, of course. (Code for that sample: Wavy Text)

I built curving trails using Catmull-Rom splines, which have the advantage of passing through all their control points (versus, say, a Beziér spline where two of the points will generally be off the curve), so it’s pretty straightforward to build them and string them together, although you do have to “guess” a little about the next point coming up.

The polygon represents the most current part of the trail, which segment you update until it reaches a current length, then “freeze” and leave behind, starting a new one.

Anyhow, take a look at those first and see if you can get a feel for the material. That should be a good start.

Check out the “Simple Trails freebie” post I just did. It might set you on the way.

@ thomas6 I need to do a max(…, .01) on the xScale to have it not error on me about setting it to 0. Also it was a little unintuitive being in the corner. But the example itself is good.

@ Chris1985 I should point out that my way was meant to accommodate texturing along the trail, but for stuff like the effect, smearing particles along a path should work out decently. The spline might still be worth looking into, though, to attempt a smoother fit.

@ thomas6  Thank you for reply! I really like the “Simple Trails freebie” but i think that is not what i need. In the video that i posted, the circle only move up and down and the trail is follow it. Anyway, your sample help me to find a way to do it, maybe a stupid way :stuck_out_tongue: , but it help me a lot, thank you very much.

@ StarCrunch  Using custom shader is kind of hard for me right now, i have no coding experience and i just study Corona myself more than a month. I really appreciate your help, i will try it later.  :) 

English isn’t my first language, so please excuse any mistakes.

I don’t want to start another topic so i write another question here. My code :

local mySetting={} mySetting.soundon = true if mySetting.soundon then audio.setVolume( 1.0 ) else audio.setVolume( 0.0 ) end function volumeoff(event) if event.phase == "ended" then mySetting.soundon = false transition.to(voloff,{time=2,alpha=1}) transition.to(volon,{time=2,alpha=0}) voloff:addEventListener( "touch", volumeon ) volon:removeEventListener( "touch", volumeoff ) end end function volumeon(event) if event.phase == "ended" then mySetting.soundon = true transition.to(voloff,{time=2,alpha=0}) transition.to(volon,{time=2,alpha=1}) volon:addEventListener( "touch", volumeoff ) voloff:removeEventListener( "touch", volumeon ) end end

If i change “mySetting.soundon = false” in line 2 then my game has no sound, but it not work in function. What did i do wrong? and how can i save my sound setting?

Well, maybe you’ll look at some of those ideas later.

You actually should start a new topic in a case like this, since some people don’t care about trails and won’t bother looking here.

A couple points: time is in milliseconds. If you want seconds, you should use 2000, not 2. Also, you probably want to return true from your touch listeners, just to avoid weird problems later.

Inside your functions, you’re not calling the important audio.setVolume (). You could wrap it up a bit and do something like:

local mySetting={} local function SetSoundState (on) mySetting.soundon = on if on then audio.setVolume(1.0) else audio.setVolume(0.0) end end SetSoundState(true) -- Start on; when you have loading code, use that here... -- Then, inside volumeoff, instead of setting soundon directly: SetSoundState(false) -- And similarly inside volumeon: SetSoundState(true)

Saving: read some of these

Please start new threads if the topic is different.

Rob

I made it! Thank you all  :smiley: