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

Author Topic: Getting a sprite to draw a shape  (Read 2116 times)

0 Members and 1 Guest are viewing this topic.

bobbyport

  • Newbie
  • *
  • Posts: 4
    • View Profile
Getting a sprite to draw a shape
« on: June 29, 2009, 02:32:30 am »
This is what I've got right now: http://codepad.org/udmkNHX9

I would like the node object to be responsible for drawing its sprite image as well as its origin (using a circle).

I could easily have it draw multiple sprites (one for its actual image the other for its origin) but I would prefer using a shape.


When I try getting the node class to inherit from sf::Sprite and sf::Shape I receive the following error:
Quote

error C2594: 'argument' : ambiguous conversions from 'Node' to 'const sf::Drawable &'

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Getting a sprite to draw a shape
« Reply #1 on: June 29, 2009, 07:53:28 am »
sf::Sprite and sf::Shape both inherit from sf::Drawable, that's why the compiler is confused.

You shouldn't inherit from them. Your class is not a sprite or a shape, it is implemented using a sprite and a shape. Public inheritance in C++ is a strong design choice, it should really be used carefully.

But what you can do is inherit from sf::Drawable and override the Render function to draw your sprite and shape.
Laurent Gomila - SFML developer

bobbyport

  • Newbie
  • *
  • Posts: 4
    • View Profile
Getting a sprite to draw a shape
« Reply #2 on: June 29, 2009, 11:39:56 pm »
Could you give me an example?

The sf::Drawable does not have a Render method.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Getting a sprite to draw a shape
« Reply #3 on: June 30, 2009, 12:05:36 am »
It does.

Code: [Select]
class Node : public sf::Drawable
{
    virtual void Render(RenderTarget& Target) const
    {
        Target.Draw(mySprite);
        Target.Draw(myShape);
    }

    sf::Sprite mySprite;
    sf::Shape myShape;
};

Node node;
window.Draw(node);
Laurent Gomila - SFML developer