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

Author Topic: Problems with Tile displaying  (Read 1659 times)

0 Members and 1 Guest are viewing this topic.

Zerod

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problems with Tile displaying
« on: January 11, 2012, 02:18:03 pm »
Hello,

i want to draw a tile from my tilemap on screen, but other tiles (like a half black half red over it) bleed into my drawing tile.

what should i do?
 
Code:
Code: [Select]

sf::RenderWindow _mainWindow;
    _mainWindow.Create(sf::VideoMode(800,600,32),"test", sf::Style::Close );
    _mainWindow.Draw(sf::Shape::Rectangle(0, 0, _mainWindow.GetWidth(), _mainWindow.GetHeight(), sf::Color(0xff,0xff,0xff)));

    sf::Image image;
    image.LoadFromFile("image.bmp");
    sf::Sprite sprite(image);

    for(int i = 0; i<10; i++)
    {  
       int posX = 60;
       int posY = 60;
       int X = 0;
       int Y = 1;
       sf::IntRect Rect(posX*X,posY*Y,posX*X+posX,posY*Y+posY);

       sprite.SetSubRect(Rect);
       sprite.SetX(60);
       sprite.SetY(i*60+20);

       _mainWindow.Draw(sprite);
    }

    _mainWindow.Display();



texus

  • Hero Member
  • *****
  • Posts: 501
    • View Profile
    • TGUI
    • Email
Problems with Tile displaying
« Reply #1 on: January 11, 2012, 06:14:57 pm »
First of all I must say that I didn't understand much of the problem, nor did I ever work with tiles or the SetSubRect function.
But I notice one thing: if I look at the code I think that you want to draw squares.
This are the values that u pass to the rectangle:
Code: [Select]
sf::IntRect Rect(0, 60, 60, 120);The last number is not the bottom position, but the height. If you were drawing squares then this should be 60.
Also if you wanted the top left piece of your image then the second number should be 0.

But if this is not the problem, then could you please try to explain the problem a little bit better?
TGUI: C++ SFML GUI

lezebulon

  • Full Member
  • ***
  • Posts: 235
    • View Profile
Problems with Tile displaying
« Reply #2 on: January 11, 2012, 07:18:15 pm »
Hi, I had the same problem using subrect. You can try to put SetSmooth to false for the sf::texture, it that still doesn't work, the workaround I found is to pre-compute 1 proper sf::texture for each tile, so you don't have to use subrect on one big image

 

anything