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

Author Topic: Sprite multiple draw ?  (Read 4728 times)

0 Members and 2 Guests are viewing this topic.

binbinhfr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Sprite multiple draw ?
« on: April 24, 2020, 07:40:30 pm »
Hi,
Before going into programing, I'd like just a clarification (from a newbie). I tested textures, sprites, and repeated textures on sprites larger than the texture, but I wanted to be sure :
in a same "pre-render drawing session",  is it possible to use the same sprite multiple times to draw it on the screen ? I suppose no...

Said in another way : in order to draw repeatively a sprite on a non regular pattern, I must create several sprites from the same texture and draw them wherever I want, yes ?

Or another example : if I want to create a repeated background that could be zoomed out as far as I want, there is no "infinite repeated sprite" available : at a moment I have to repeat manually a texture by duplicating enough sprites to cover my screen ? (even if the sprite itself, within its limits, can be constructed from a repeated texture)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite multiple draw ?
« Reply #1 on: April 24, 2020, 08:30:36 pm »
Quote
in order to draw repeatively a sprite on a non regular pattern, I must create several sprites from the same texture and draw them wherever I want, yes ?
No. If you mean this:
sprite.setPosition(...);
target.draw(sprite);

sprite.setPosition(...);
target.draw(sprite);

...
... then it is perfectly possible.

Quote
if I want to create a repeated background that could be zoomed out as far as I want, there is no "infinite repeated sprite" available : at a moment I have to repeat manually a texture by duplicating enough sprites to cover my screen ?
Yes. Or maybe there's some trick that you can find with shaders?
Laurent Gomila - SFML developer

binbinhfr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Sprite multiple draw ?
« Reply #2 on: April 24, 2020, 08:45:11 pm »
... then it is perfectly possible.

Oh, so I was right to ask this newbie question  ;D

I'll have a look at the shaders.

Thanks for your help and for SFML.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sprite multiple draw ?
« Reply #3 on: April 25, 2020, 12:41:35 am »
Hi.

if I want to create a repeated background that could be zoomed out as far as I want, there is no "infinite repeated sprite" available : at a moment I have to repeat manually a texture by duplicating enough sprites to cover my screen ? (even if the sprite itself, within its limits, can be constructed from a repeated texture)

You can create an infinitely repeated sprite by using a repeated texture and some offset tricks:
https://en.sfml-dev.org/forums/index.php?topic=14382.msg101088#msg101088

(click to show/hide)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

binbinhfr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Sprite multiple draw ?
« Reply #4 on: April 25, 2020, 10:05:32 am »
thx Hapax.

Very useful.
But if I understood correctly, this large sprite will be limited by the max size of a single sprite/texture in my GPU. So If I want a larger background, I have to repeat this sprite manually, right ?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sprite multiple draw ?
« Reply #5 on: April 26, 2020, 11:59:59 pm »
A sprite doesn't have a limit on its size; its size is only really arbitrary values.
A texture does have a limit so as long as the repeated texture is stored fine in a sf::Texture, the sf::Sprite can be any size and repeat any number of times.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

binbinhfr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Sprite multiple draw ?
« Reply #6 on: April 27, 2020, 12:10:55 am »
ok, thx for this clarification.
All is working fine, now that I understand all this stuff  8)

 

anything