SFML community forums

Help => Graphics => Topic started by: doingit on April 06, 2016, 12:33:41 am

Title: Is it possible to store shapes into sprites?
Post by: doingit 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.
Title: Re: Is it possible to store shapes into sprites?
Post by: Hapax 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.
Title: Re: Is it possible to store shapes into sprites?
Post by: doingit 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.
Title: Re: Is it possible to store shapes into sprites?
Post by: eXpl0it3r 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.
Title: Re: Is it possible to store shapes into sprites?
Post by: Hapax 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)