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

Author Topic: easiest way to repeat a texture to fill a rectangle  (Read 2393 times)

0 Members and 1 Guest are viewing this topic.

dubesinhower

  • Newbie
  • *
  • Posts: 6
    • View Profile
easiest way to repeat a texture to fill a rectangle
« on: May 05, 2013, 04:41:59 am »
i'm trying to use a texture as a background, but when i use a sprite set with a texture that is set to repeat, it only shows the texture one time and it doesn't repeat. am i not using this function correctly?

i also tried applying the texture to a rectangle shape, but it just stretches the texture to fill the box one time.

any tips would be appreciated!
« Last Edit: May 05, 2013, 08:44:39 am by dubesinhower »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: easiest way to repeat a texture to fill a rectangle
« Reply #1 on: May 05, 2013, 08:45:51 am »
You must use a textureRect which is bigger than the texture size, and set the texture as repeated (texture.setRepeated(true)).

This is explained in the tutorial.
Laurent Gomila - SFML developer

dubesinhower

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: easiest way to repeat a texture to fill a rectangle
« Reply #2 on: May 05, 2013, 10:59:32 pm »
the texture is set to repeat, and the area is huge compared to the texture. but it only stretches a single copy of the texture to fill the the rectangle.

edit: derp, didnt notice the need for textureRect as apposed to rectangleShape. ill check it out

edit: k figured it out. didn't know you had to set a sprite's textureRect to be the size of the rectangle i wanted to fill. thanks for the help!
« Last Edit: May 05, 2013, 11:16:33 pm by dubesinhower »