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

Author Topic: Is it possible to store shapes into sprites?  (Read 3310 times)

0 Members and 1 Guest are viewing this topic.

doingit

  • Newbie
  • *
  • Posts: 17
    • View Profile
Is it possible to store shapes into sprites?
« on: April 06, 2016, 12:33:41 am »
This is probably a question that has already been asked before already, but is it possible to store shapes as sprites? (convert)

Having objects that contain sprites, I'd rather not have to contain shapes as well. Since their behaviors are similar, I'd figured there'd be some easy way to convert them.

My current understanding is that I can assign over the texture, but that isn't really what I want; I want the shape as well.

And what I'm trying not to do is: draw the shape onto a render texture, then acquiring that texture(the shape) from renderTexture and storing it into a sprite.

Any shortcuts?
Thanks.

Hapax

  • Hero Member
  • *****
  • Posts: 3367
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Is it possible to store shapes into sprites?
« Reply #1 on: April 06, 2016, 02:31:03 am »
Sprites displays textures in a quad. That's the thing that they do. Therefore, if you want a sprite to show a shape, it must be rendered/rasterized first.

If you want to store something like sprites in a container with shapes, you can use a rectangle shape instead of a sprite.

If you just need to be able to access them using a pointer (or reference) of the same type, you can use a pointer of type sf::Drawable instead since they all inherit from that base class.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

doingit

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Is it possible to store shapes into sprites?
« Reply #2 on: April 06, 2016, 06:24:45 am »
What is the significant difference between rectangle shape and sprite? other than rectangle shape having adjustable points.

More than likely, I will go with shapes, since "they can" achieve the projection of textures in similar ways to the sprite class and uniform with all other types of shape; single container.

Thanks.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10913
    • View Profile
    • development blog
    • Email
Re: Is it possible to store shapes into sprites?
« Reply #3 on: April 06, 2016, 08:29:58 am »
The main point is that sprite requires you to use a texture, while a rectangle shape allows you to use one, but doesn't require it.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3367
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Is it possible to store shapes into sprites?
« Reply #4 on: April 06, 2016, 09:17:27 pm »
Sprite also trims off that excess features that isn't commonly required in a sprite: outlines.

Indeed. Rectangle Shape can do all that sprite can do and more. Sprite is simply a more compact and dedicated class for displaying sprites (obviously ;D)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*