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

Author Topic: Problem with sf::IntRect  (Read 6057 times)

0 Members and 1 Guest are viewing this topic.

woskaz0n

  • Newbie
  • *
  • Posts: 14
    • View Profile
Problem with sf::IntRect
« 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...


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...





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

Thanks in advance!
Realism is what makes games suck. - Wouter van Oortmerssen

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Problem with sf::IntRect
« Reply #1 on: November 30, 2008, 04:40:08 pm »
Rect2 should be :
Code: [Select]
sf::IntRect Rect2(45, 0, 90, 45);
SFML / OS X developer

woskaz0n

  • Newbie
  • *
  • Posts: 14
    • View Profile
Problem with sf::IntRect
« Reply #2 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!
Realism is what makes games suck. - Wouter van Oortmerssen

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Problem with sf::IntRect
« Reply #3 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').
SFML / OS X developer

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
Problem with sf::IntRect
« Reply #4 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.