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

Author Topic: [newb] Sprite for every instance?  (Read 2467 times)

0 Members and 1 Guest are viewing this topic.

hagel

  • Newbie
  • *
  • Posts: 23
    • View Profile
[newb] Sprite for every instance?
« on: November 20, 2010, 06:06:31 pm »
I don't know a lot about SFML but it makes me think that you need an sprite "object" for every instance of an actor. Is that right?
I'm transitioning from Allegro where you just pass the image and blit the part you want with srcX,srcY,width,height from a BITMAP to a buffer(and finally to the screen). Is there a way to do that in SFML? I kinda don't trust "renderApp.draw(image);", it's too abstracted.
I really want to start using SFML seriously because of the networking capabilities.
I hope you can shed some light on my curiosity.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
[newb] Sprite for every instance?
« Reply #1 on: November 20, 2010, 07:21:43 pm »
If you don't like things that is abstracted then you shouldn't really do something object-oriented.

Anyway yes, a Sprite holds the reference to an Image. This way the different data is separated and more "abstracted". sf::Image holds anything concerning the image data and a sf::Sprite instance encapsulates everything which has to do with actually rendering the image data. So every actor should have a sprite with an image set from a resource manager.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[newb] Sprite for every instance?
« Reply #2 on: November 20, 2010, 07:28:17 pm »
You can think of sf::Sprite as something that holds your srcX, srcY, width, height and BITMAP. And sf::Sprite::Draw is simply equivalent to Draw(srcX, srcY, width, height, BITMAP).

It's not more complicated/abstracted than that.
Laurent Gomila - SFML developer

hagel

  • Newbie
  • *
  • Posts: 23
    • View Profile
[newb] Sprite for every instance?
« Reply #3 on: November 20, 2010, 07:43:43 pm »
Don't get me wrong. I like abstraction, it's just that I want a little more control over my image.
I'm just having a hard time understanding how I can make the animation simple enough. Sprite sheets and all that jazz you know.
If I want more than one frame in my animation(lol?) I need more than one Sprite in my actor instance, right? Something like Sprite spr[5]?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
[newb] Sprite for every instance?
« Reply #4 on: November 20, 2010, 07:51:27 pm »
You could but that would be inefficient.

Your interested in this function: http://sfml-dev.org/documentation/2.0/classsf_1_1Sprite.htm#ae8e8be077534c0b8704e59b0ea4cf9a

Also I think animation has already been covered in this forum or the Wiki.
http://sfml-dev.org/wiki/en/sources
Check it out, there is several different.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio