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

Author Topic: Using one image and taking sectors?  (Read 1414 times)

0 Members and 1 Guest are viewing this topic.

Sivak

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Using one image and taking sectors?
« on: March 21, 2010, 04:28:28 am »
Hey all.  I wondered if it was possible to do something like have a portion of an image be used as a sprite?

Say I had a 50x50 pixel image with 4 25x25 pixel frames on it.  Could I take each of these frames using just the one image and make 4 sprites of it or does it HAVE to be a separate image file for each?

Thanks.

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Using one image and taking sectors?
« Reply #1 on: March 21, 2010, 05:55:04 am »
Yes! You can do that with SetSubRect.

Here is an exerpt from the tutorial:

Quote
If you want to draw only a sub-rectangle of the original image, you can change the SubRect parameter of the sprite :

Sprite.SetSubRect(sf::IntRect(10, 10, 20, 20));

Here we will only display a sub-rectangle of the image, going from pixel (10, 10) to pixel (20, 20).