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

Author Topic: Can you draw a part of a sprite instead of the whole thing?  (Read 4407 times)

0 Members and 1 Guest are viewing this topic.

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Can you draw a part of a sprite instead of the whole thing?
« on: November 17, 2011, 04:43:50 am »
Hello,
I want to incorporate frame-based animation in my game, but I don't want to have to draw and load each individual frame as a different image and sprite.  My solution is to draw all the frames on one image, load it, then draw in the window only a single part of that image, the part I want it to display.
Is there a built-in function that I could use to:
A. Draw only part of a Sprite, or
B. Apply image effects on only one section of an image, so I could apply 100% transparency on the parts I don't want to display?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Can you draw a part of a sprite instead of the whole thing?
« Reply #1 on: November 17, 2011, 07:53:33 am »
A sprite is already a part of an image. Use its SetSubRect function.
Laurent Gomila - SFML developer

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Can you draw a part of a sprite instead of the whole thing?
« Reply #2 on: November 17, 2011, 03:35:21 pm »
Yes, you are using (or want to use) a "spritesheet".

Look at something like TexturePacker to load all your images onto a spritesheet, the load the image in SFML. Use SetSubRect to get the next frame you want, then simply draw it in the usual way.

We added some extra flexibility in our system, which reads an XML file each frame and sets parameters (scale, rotate, flip, etc) which allows very quick ways to add extra stuff to your animation.
SFML 2.1

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Can you draw a part of a sprite instead of the whole thing?
« Reply #3 on: November 17, 2011, 03:52:27 pm »
Ah, thank you. :)

 

anything