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

Author Topic: Texture appears in a weird way (Solved)  (Read 1515 times)

0 Members and 3 Guests are viewing this topic.

Toad The Mushroom coder

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Texture appears in a weird way (Solved)
« on: January 01, 2018, 12:47:37 pm »
Hello!
So recenty I tried to set a texture for a floor sprite I was making for a test I was doing. I was trying to create a Sprite named floor, in which the texture "terrain" would repeat itself, creating something similar to the ground in Super Mario Bros. Here is my code, where I define the afore mentioned:

sf::Texture terrain;
terrain.create(50, 50);
if (!terrain.loadFromFile("img/tile.png"))
{
      std::wcout << L"No tile.png exists";
}
terrain.setRepeated(true);

sf::Sprite floor;
floor.setScale(10000.f, 1000000000.f);
floor.setPosition(0.f, 4700.f);
floor.setTexture(terrain);
 

For reference, the image tile.png is the following and its size is 50*50 (pixels)


However, when I draw the floor, I get this:


The brown box right Mario is the floor Sprite I defined above.
As you can see, the texture "terrain" is not repeated across the srite as intended, but rather the floor has a brown texture. How can I fix this? Am I doing something wrong?
« Last Edit: January 04, 2018, 04:10:27 pm by Toad The Mushroom coder »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Texture appears in a weird way
« Reply #1 on: January 01, 2018, 05:16:35 pm »
Please read the docs more carefully: to get a repeated texture, you need to use a bigger texture rect, not a bigger scale factor.
Laurent Gomila - SFML developer

 

anything