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

Author Topic: Repeating a texture when using a tileset  (Read 6326 times)

0 Members and 3 Guests are viewing this topic.

Yaxlat

  • Newbie
  • *
  • Posts: 14
    • View Profile
Repeating a texture when using a tileset
« on: March 03, 2015, 11:15:38 pm »
For my basic "obstacle" object, I have sprites which have a width and height which is larger than those of the textures they are using. In order fix this, I use texture.setRepeated(true). However I want to use a tileset such as this one when I have multiple textures, using the sprite.setTextureRect() function in order to select the right texture. At this point, I can no longer have a repeating texture. How can I fix this issue, such that I can having a repeating texture for a sprite, whilst using a tileset and the setTextureRect() function SFML provides?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Repeating a texture when using a tileset
« Reply #1 on: March 03, 2015, 11:22:56 pm »
How about just drawing your sprite repeatedly at all the positions where you want it?
Yes, that's a lot of draw calls and not the "optimal" solution, but usually it is "good enough" performance wise.
Or you could use a sf::VertexArray - see also the tutorial entry.
You could of course also just use different (repeating) textures for each of your sprites - although that feels kinda horrible, but it would work...
« Last Edit: March 03, 2015, 11:37:06 pm by Jesper Juhl »

Yaxlat

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Repeating a texture when using a tileset
« Reply #2 on: March 03, 2015, 11:35:57 pm »
How about just drawing your sprite repeatedly at all the positions where you want it?
Yes, that's a lot of draw calls and not the "optimal" solution, but usually it is "good enough" performance wise.
Or you could use a sf::VertexArray - see also the tutorial entry.

Is there no simpler solution? I have a "draw" function which takes a sprite and a position, and I would be great if the texture was looped for the sprite object itself.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Repeating a texture when using a tileset
« Reply #3 on: March 04, 2015, 07:36:33 am »
Quote
Is there no simpler solution?
Nop.
Laurent Gomila - SFML developer

Yaxlat

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Repeating a texture when using a tileset
« Reply #4 on: March 04, 2015, 08:56:33 am »
Quote
Is there no simpler solution?
Nop.

Can one sprite support multiple textures in it at once?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Repeating a texture when using a tileset
« Reply #5 on: March 04, 2015, 08:58:51 am »
No.

Yaxlat

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Repeating a texture when using a tileset
« Reply #6 on: March 04, 2015, 08:59:53 am »
No.

Ok thanks a lot for your help :)
It seems the best way to do it for now is just to add a "repeating" boolean to my draw function, and then draw the sprite multiple times. Thanks for your input.

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: Repeating a texture when using a tileset
« Reply #7 on: March 04, 2015, 11:15:30 am »
When using a sprite atlas as shown, do yourself a favor and look at sf::VertexArray. It's just the best solution to your problem and scales in the long run performance-wise.
I know that for sure, as I just conquered the same "problem" ;)

Yaxlat

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Repeating a texture when using a tileset
« Reply #8 on: March 04, 2015, 07:18:37 pm »
When using a sprite atlas as shown, do yourself a favor and look at sf::VertexArray. It's just the best solution to your problem and scales in the long run performance-wise.
I know that for sure, as I just conquered the same "problem" ;)

Ok I will! Thanks a lot for your input, there's a chance you've saved me a lot of headache later!