SFML community forums

Help => Graphics => Topic started by: woskaz0n on November 30, 2008, 04:11:56 pm

Title: Problem with sf::IntRect
Post by: woskaz0n on November 30, 2008, 04:11:56 pm
hi everybody again  :D

I´m sorry that I´ve to ask quite a lot, but sometimes I´m unable to find a possible solution.

This time I want to load some images from a sprite sheet, like this...
(http://img155.imageshack.us/img155/8485/sheetcl8.jpg)

For this I use the sf::IntRect function... but I don´t know how to set the parameters. After I tried a few things, I allready know that the two last parameters give the size of the sprite.
So I guess the other two are standing for the position, but this won´t work
Code: [Select]

sf::IntRect Rect(0, 0, 45, 45);   /* Everything allright... the first sprite is shown.*/

sf::IntRect Rect2(45, 0, 45, 45); /*This should cut out the second sprite, but when I display it, it appears just a black screen */

sf::IntRect Rect(-45, 0, 45, 45); /*What happens now, you can see in the screenshot below...



(http://img155.imageshack.us/img155/6838/mapum4.png)

So, what have i to do, that the second sprite is shown on the screen?

Thanks in advance!
Title: Problem with sf::IntRect
Post by: Hiura on November 30, 2008, 04:40:08 pm
Rect2 should be :
Code: [Select]
sf::IntRect Rect2(45, 0, 90, 45);
Title: Problem with sf::IntRect
Post by: woskaz0n on November 30, 2008, 04:58:05 pm
Quote from: "Hiura"
Rect2 should be :
Code: [Select]
sf::IntRect Rect2(45, 0, 90, 45);


Thanks for your quick answer, it works fine. But i don´t know why  :D
Could someone give me a brief statement which parameter I´m using for which position, please?
Thank you very much!
Title: Problem with sf::IntRect
Post by: Hiura on November 30, 2008, 05:21:34 pm
The doc explains it.  :wink:

If your rect is defines by two points (upper-left and bottom-right coins) : UL(X;Y) and BR(X';Y'). Your rect will be : sf::IntRect rect(X, Y, X', Y').
Title: Problem with sf::IntRect
Post by: Wizzard on December 01, 2008, 04:30:28 am
Quote from: "Hiura"
your rect is defines by two points (upper-left and bottom-right coins)

As Hiura said, you need two points to make a rectangle in SFML, the upper left corner of the rectangle and the bottom right corner of the rectangle:
Code: [Select]
(x1, y1)----
|          |
|          |
----(x2, y2)

sf::IntRect(x1, y1, x2, y2);

Note that the third and fourth parameters are not width and height, but coordinates.