SFML community forums
Help => Graphics => Topic started by: Sivak 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.
-
Yes! You can do that with SetSubRect.
Here is an exerpt from the tutorial (http://www.sfml-dev.org/tutorials/1.5/graphics-sprite.php):
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).