Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Comet tail  (Read 2015 times)

0 Members and 1 Guest are viewing this topic.

Paijan

  • Newbie
  • *
  • Posts: 4
    • View Profile
Comet tail
« on: July 09, 2015, 01:40:53 pm »
I'm writing a game in which moving objects leave tails behind themselves, like comets. Objects can be moved either by player input or mathematical function (e.g. on sinusoid).

I couldn't find a good way to perform this so I tried the simplest one - creating CircleShape in regular intervals in objects' positions. And it worked, because of simplicity, but later on it became a performance bottleneck. It's snappy and the tails sometimes break -pics.

How to do it properly? Thor particles?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Comet tail
« Reply #1 on: July 09, 2015, 01:55:22 pm »
If you want the tail to be contiguous and stay behind you could simply draw a line between each of the points denoting the previous positions.
If the tail is supposed to "fade out" then something like Thor's particles may be better suited.
Or you could use a shader to draw the tail I guess.

Paijan

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Comet tail
« Reply #2 on: July 09, 2015, 02:09:42 pm »
Quote
If you want the tail to be contiguous and stay behind you could simply draw a line between each of the points denoting the previous positions.

You mean storing coordinates each frame and appending it to VertexArray?

EDIT: Well, it really works fine, only now I can't alter line thickness
« Last Edit: July 09, 2015, 02:19:07 pm by Paijan »

kitteh-warrior

  • Guest
Re: Comet tail
« Reply #3 on: July 09, 2015, 05:12:56 pm »
can't alter line thickness

This shows how it is possible with a sf::VertexArray. If that doesn't work for you, the mathematical concepts behind it should help you.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Comet tail
« Reply #4 on: July 10, 2015, 09:58:30 am »
This is a really typical use case for particles. The more flexibility you add to a handcrafted solution, the closer it will get to a freely configurable particle system ;)

In the Thor fireworks example, I've done exactly that -- tails for the firework explosions. You can have a look at it, even in case you don't end up using Thor.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Paijan

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Comet tail
« Reply #5 on: July 11, 2015, 03:33:02 pm »
Thank you for your replies.

I decided using VertexArray and the tail works perfectly. I even tried fading it by iterating through all vertices and changing their alpha values calculated from quadratic function (to make it smooth). It looks nice.

Should I somehow dispose of faded vertices? Because they are faded, but they still exist in memory and are drawn each frame.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Comet tail
« Reply #6 on: July 11, 2015, 03:39:49 pm »
Yes, definitely remove them. Maybe not every frame, because removing from the beginning of a vector is expensive, but once a second or so.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: