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

Author Topic: Spritesheet with Rect  (Read 3134 times)

0 Members and 1 Guest are viewing this topic.

Resnis

  • Newbie
  • *
  • Posts: 7
    • View Profile
Spritesheet with Rect
« on: April 03, 2010, 12:15:18 am »
I know, that there are libraries on the wiki, but i just wanted to go trough the process myself, of using spritesheets.
The spritesheet is 32x16 and i created an Rect, that holds the positions of the sprites in the sprite sheet.
I know that giving an rectangle as coordinates doesn't work, but how do i get around this?
Code: [Select]
sf::Image Image;
    if (!Image.LoadFromFile("spritesheet.png"))
        return EXIT_FAILURE;

sf::Shape Rect[ 2 ];
Rect[0].SetPointPosition(1, 0, 0);
Rect[0].SetPointPosition(2, 16, 0);
Rect[0].SetPointPosition(3, 16, 16);
Rect[0].SetPointPosition(4, 0, 16);

Rect[1].SetPointPosition(1, 16, 0);
Rect[1].SetPointPosition(2, 32, 0);
Rect[1].SetPointPosition(3, 32, 16);
Rect[1].SetPointPosition(4, 16, 16);

    sf::Sprite Sprite(Image);
Sprite.SetSubRect(Rect[0]);

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Spritesheet with Rect
« Reply #1 on: April 03, 2010, 10:14:23 am »
SetSubRect wants a sf::IntRect, not a sf::Shape. Read the documentation and tutorials please ;)
Laurent Gomila - SFML developer

Resnis

  • Newbie
  • *
  • Posts: 7
    • View Profile
Spritesheet with Rect
« Reply #2 on: April 03, 2010, 02:45:20 pm »
It's asking me coordinates of Left, Top, Right and Bottom, but I am already giving them.
Code: [Select]
sf::IntRect Rect[ 2 ];
Rect[0].Left(0, 0);
Rect[0].Top(16, 0);
Rect[0].Right(16, 16);
Rect[0].Bottom(0, 16);

Quote
term does not evaluate to a function taking 2 arguments

So i guess it needs other values, but what? And, btw, in what order are the points? I mean is Left meant to be top-left, or bottom-left?

K-Bal

  • Full Member
  • ***
  • Posts: 104
    • View Profile
    • pencilcase.bandcamp.com
    • Email
Spritesheet with Rect
« Reply #3 on: April 03, 2010, 03:16:47 pm »
These are axis aligned rects so you don't need 4 points but 2 points.

Left is point1.x, Right is point2.x, Top is point1.y and Bottom is point2.y.
Listen to my band: pencilcase.bandcamp.com

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Spritesheet with Rect
« Reply #4 on: April 03, 2010, 03:18:58 pm »
Again, this is in the documentation. You can easily see that Left, Top, Right and Bottom are ints, not points.
Laurent Gomila - SFML developer

 

anything