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

Author Topic: Sprite Management question  (Read 4055 times)

0 Members and 1 Guest are viewing this topic.

Chivos

  • Newbie
  • *
  • Posts: 19
    • View Profile
Sprite Management question
« on: January 07, 2013, 08:16:47 pm »
I am working on an image manager. To do so, I have used a virtual function in my class to do my drawing.

Code: [Select]
virtual void Render(sf::RenderTarget& App) const;

Code: [Select]
void Graphics::Render(sf::RenderTarget& App) const
{
    App.Draw(spriteBJtable);
}

The issue is that I would like to use this same function to draw other sprites, but it seems that I cannot overload the function to include a string for the sprite.

Is there anyway to allow the sprite being drawn to be sent into the function so that I can use this draw function to draw multiple sprites in my manager? Any help would be greatly appreciated.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Sprite Management question
« Reply #1 on: January 07, 2013, 08:25:45 pm »
The issue is that I would like to use this same function to draw other sprites, but it seems that I cannot overload the function to include a string for the sprite.
Why exactly can't you overload it? Is the function overriden from sf::Drawable::Draw() -- or why is it virtual?

And what does this have to do with strings?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Chivos

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Sprite Management question
« Reply #2 on: January 07, 2013, 08:31:43 pm »
The class is inherting from drawable. Every time i try to overload the function, I get a compiler error that says the class is a pure virtual class. The error brings me to the Render(sf::RenderTarget& App) const function in drawable.hpp.

The purpose of the string was to allow a string to pass in so I could set it to a different sprite. something like:

Code: [Select]
void load(std::string file)
{
imgBGone.LoadFromFile(file);
}

so that I can set the name of the sprite to load.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Sprite Management question
« Reply #3 on: January 07, 2013, 08:45:46 pm »
Every time i try to overload the function, I get a compiler error that says the class is a pure virtual class.
Classes cannot be virtual, they can be abstract and have pure virtual methods. And this error happens, if you do not define the function, not if you overload it.

The purpose of the string was to allow a string to pass in so I could set it to a different sprite. something like:
Now there is load, and an image. Before you talked about Render, and sprites.

You should really express yourself more clearly, or even better, illustrate with a minimal complete example what you want to achieve and where your problem is. Please read this thread.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Chivos

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Sprite Management question
« Reply #4 on: January 07, 2013, 09:01:04 pm »
Alright, let me try to clear up my question a bit ;)

Code: [Select]

class Graphics : public sf::Drawable
{
    public:
        Graphics(){};
        ~Graphics(){};

virtual void Render(sf::RenderTarget& App) const;
void loadBJtable();
void sprite_loadBJtable();

void loadBCard();
void sprite_loadBCard();



    private:

sf::Image BJtable;
sf::Sprite spriteBJtable;

sf::Image BCard;
sf::Sprite spriteBCard;

};




Currently, to display the BJtable, I am using
Code: [Select]
virtual void Render(sf::RenderTarget& App) const;
[code]

[code]
void Graphics::Render(sf::RenderTarget& App) const
{
    App.Draw(spriteBJtable);
}

in main
Code: [Select]
Graphic.Render(App);

I would like to be able to use the virtual function to also display spriteBCard, not just spriteBJtable. ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite Management question
« Reply #5 on: January 07, 2013, 09:25:17 pm »
Pleeeeease, use the code=cpp tag.
Laurent Gomila - SFML developer

Chivos

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Sprite Management question
« Reply #6 on: January 07, 2013, 09:43:05 pm »
ya, I pretty much failed on the clearing up of the question. I make sure to use proper code tags for future posts.

Anyway, I have tried to overload the virtual function but I get an error that says that the function cannot be overloaded. I think I am looking at this the wrong way and I need to implement a different strategy. What brought this all on was that I wanted my sf::Image and sf::Sprite to be private. After asking on these boards, someone mentioned inheriting from sf::Drawable, and writing a virtual function to display the sprite. I have accomplished this through the code i have posted in the forum; however, I am implementing a second  sf::Image and sf::Sprite in private. I am attempting to follow the same method; however,
 
Code: [Select]
void Graphics::Render(sf::RenderTarget& App) const
{
    App.Draw(spriteBJtable);
}

will only display spriteBJtable.

So, I was trying to figure out a way to, App.Draw(chosensprite), instead of a fixed one; however, I have not found a way to do so.

Hopefully this helps clear things up a bit.

Chivos

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Sprite Management question
« Reply #7 on: January 07, 2013, 10:00:02 pm »
Wow.... nvm I figured it out.. sorry for all the confusion.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Sprite Management question
« Reply #8 on: January 07, 2013, 10:11:01 pm »
You still didn't use the right tag.

Write your code [code=cpp]like this[/code] (3rd entry of the rightmost dropdown field).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: Sprite Management question
« Reply #9 on: January 07, 2013, 11:47:22 pm »
void Graphics::Render(sf::RenderTarget& App) const
{
    App.Draw(spriteBJtable);
    App.Draw(spriteBCard); // ???
}