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

Author Topic: How to slant (place obliquely) a Sprite or Drawable?  (Read 1357 times)

0 Members and 1 Guest are viewing this topic.

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
How to slant (place obliquely) a Sprite or Drawable?
« on: August 20, 2017, 01:30:33 am »
Hi Ladies and Guys

Could you tell me how to slant a Sprite? I suppose it should be something related to the Transform class, but I googled and there's no info. I don't even know if it's possible. If it is, could you give me an example?

Thanks

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How to slant (place obliquely) a Sprite or Drawable?
« Reply #1 on: August 20, 2017, 02:35:19 am »
sf::Transformables don't allow for slant/skew transformations.

Two options here:
1) use a vertex array and place the corners where you want them. However, be careful to make sure that the quad is not distorted. Which brings me to...
2) use Selba Ward's Elastic Sprite 8)


(Selba Ward forum thread)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: How to slant (place obliquely) a Sprite or Drawable?
« Reply #2 on: August 20, 2017, 04:05:06 am »
Hi Hapax

The problem is that I have a sprite that contains a Texture (graphic) that I need to slant, so a VertexArray won't solve it.

Selba Ward, I didn't finish to see the demo, and already realise that it's wonderful. Actually I regret that there is not a translation to C#. (Wouldn't you do it?  ;D)

But it occurred to me to move the pixel lines to get the effect.

Thank you very much, anyway. (and hope to see the binding  :)))


Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How to slant (place obliquely) a Sprite or Drawable?
« Reply #3 on: August 20, 2017, 08:45:36 pm »
You can use an sf::VertexArray instead of the sf::Sprite...

That Selba Ward demo video is already a little bit old; there are numerous additions/improvements since then 8)
I have very little experience with C# so I couldn't port/bind Selba Ward to/for it. If anyone else is interested in doing that, let me know ;)

If the task you want to achieve is image manipulation - directly affect the image pixels - then you will need to do that manually; this is not something SFML does. However, you can use a render texture to draw the skewed object and then create an image from the render texture...
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything