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

Author Topic: SimpleSprite  (Read 5579 times)

0 Members and 2 Guests are viewing this topic.

ZenonSeth

  • Newbie
  • *
  • Posts: 19
    • View Profile
SimpleSprite
« on: February 01, 2013, 07:26:04 pm »
I was doing some testing yesterday on a project I'm working on, and I realized that drawing the sf::RectangleShape (which I had a lot of) wasn't performing as fast as using a sf::Sprite. However, I also wanted a setSize functionality and I was planning to do something which would have benefited from a setVertexColor function.

So, this isn't exactly a project, but I wrote a SimpleSprite class which fullfills those needs.
It should also duplicate all functionality of a sf::Sprite, so you should (in theory) be able to replace any sf::Sprite objects with SimpleSprite and would not be required to do any other code changes. I've seen a couple of posts where people were talking about stuff like this, so I decided to post this.

Here's the public functionality of SimpleSprite:
Code: [Select]

    SimpleSprite ( );

    explicit SimpleSprite ( const sf::Texture &texture );

    SimpleSprite ( const sf::Texture &texture, const sf::IntRect& rect );

    void setSize ( const sf::Vector2f &size);

    void setSize ( float size_x, float size_y );

    void setTexture ( const sf::Texture &texture, bool updateTextureRect = false );

    void setTextureRect ( const sf::IntRect &rect );

    void setColor ( sf::Color color );

    void setVertexColor ( unsigned int index, sf::Color color );

    // getters

    const sf::Vector2f& getSize () const;

    const sf::Texture* getTexture () const;

    const sf::IntRect& getTextureRect () const;

    // Warning: This function may not return correct results if you have used setVertexColor(..)
    // This function is the equivalent of calling getVertexColor(0)
    const sf::Color& getColor () const;

    const sf::Color& getVertexColor ( unsigned int index ) const;


The .hpp and .cpp are attached.
Edit: Updated - the default behavior of setTexture so that updateTextureRect is false by default.

[attachment deleted by admin]
« Last Edit: February 01, 2013, 08:34:51 pm by ZenonSeth »

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: SimpleSprite
« Reply #1 on: February 01, 2013, 08:04:45 pm »
Post it in the wiki, it's better than to attach it to a thread that may die and not be seen in long time.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

ZenonSeth

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: SimpleSprite
« Reply #2 on: February 01, 2013, 09:26:14 pm »
I see, I should do that, but I'm not sure how how (if at all possible) to upload files there, so I'm just going link to this thread for this.

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: SimpleSprite
« Reply #3 on: February 02, 2013, 03:31:51 am »
All you need is a Github account and you can modify the wiki and add your sources and a short explanation in a new page, and of course link the page to the sources menu.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Re: SimpleSprite
« Reply #4 on: February 02, 2013, 09:31:27 pm »
void setVertexColor ( unsigned int index, sf::Color color );
 

Nice feature!
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

 

anything