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

Author Topic: Conceptualizing "Ghosting" Sprite Movement  (Read 2665 times)

0 Members and 1 Guest are viewing this topic.

JGrieco42

  • Newbie
  • *
  • Posts: 6
    • View Profile
Conceptualizing "Ghosting" Sprite Movement
« on: August 29, 2014, 07:58:11 pm »
I have an animated sprite of a walking character.  I would like to achieve something similar to Castlevania:SoTN's "ghosting" effect, seen in this gif when the character is falling:

and in this image (to a lesser extent):


I'm thinking of handling it by:
1) drawing the sprite to a rendertexture.  Successive frames would then
2) offset the sprite by whatever camera movement has taken place,
3) doing a color/alpha pass on the existing "ghosted" render texture,
4) rendering the current sprite in it's normal position, and repeating.

Am I overthinking this and should just use a collection of sf::Sprites along with some setColor's, or is the gpu be the best way to go?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Conceptualizing "Ghosting" Sprite Movement
« Reply #1 on: August 29, 2014, 08:09:36 pm »
Quote
Am I overthinking this and should just use a collection of sf::Sprites along with some setColor's, or is the gpu be the best way to go?

I'm gonna go with yes.  In this case I don't see any benefit to using a RenderTexture, since your proposal sounds like it would simply draw the sprite to the render texture then draw it to the window, when you could just draw it to the window in the first place.  Plus, it's hard to imagine this being a performance bottleneck (unless you expect to be "ghosting" hundreds of enemies, not just the player).

It might be possible to use a vertexarray here, since the player and his "ghosts" presumably all share the same spritesheet, though I think you want different colors/opacities for each "ghost" so even that is likely to be more trouble than it's worth.
« Last Edit: August 29, 2014, 08:16:05 pm by Ixrec »

Sherman

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Conceptualizing "Ghosting" Sprite Movement
« Reply #2 on: August 31, 2014, 01:49:57 am »
This should be fairly easy to implement (I've already done it myself). I had a struct that would store the sf::Vector2f position of the character and a sf::IntRect that would store the current animation's frame. Every X frames I would create that struct, fill it with the necessary data and push it into a limited queue.

I could control the length of the trail by setting the size of the queue and I could tweak the interval at which I stored the information to control how fluid the ghost images move.

Every draw call I would draw the whole queue from back to front (because you want newer ghosts being drawn over older ghosts). Using the information from the struct I could put the ghost image at the same position and in the same animation state as the normal character that was drawn on the frame I stored the information. I could fade out the ghosts by using a fixed color value - the position of the ghost in the queue. 

I only ended up using one sf::Sprite that used the same texture as the sf::Sprite I used to draw the normal character. I've had no performance issues doing it this way.
« Last Edit: August 31, 2014, 01:51:53 am by rpt_stash »

 

anything