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

Author Topic: SFML 2.0 -> SetPointColor(...)  (Read 5109 times)

0 Members and 1 Guest are viewing this topic.

Orezar

  • Newbie
  • *
  • Posts: 38
    • View Profile
SFML 2.0 -> SetPointColor(...)
« on: February 24, 2012, 05:24:19 pm »
Hello,

I´m exporting my code from SFML 1.6 to SFML 2.0
(more Work than i thought :P) but I have one Problem.
I saw that there is for sf::Shape and sf::RectangleShape no
SetPointColor function, I need this for my design.

Why this function don´t exist anymore, or I´m looking at
the false place? If it don´t exist anymore, can u Implement
it for SFML 2.0?

Sorry for my bad Englisch and thanks in advance!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
SFML 2.0 -> SetPointColor(...)
« Reply #1 on: February 24, 2012, 05:45:08 pm »
For simplicity, sf::Shape now only provides one color. If you need more flexibility, take a look at sf::Vertex and sf::VertexArray.

There have already been threads about this, use the search function...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Orezar

  • Newbie
  • *
  • Posts: 38
    • View Profile
SFML 2.0 -> SetPointColor(...)
« Reply #2 on: February 24, 2012, 07:23:04 pm »
Is there no easier Way to do this with less code? :(

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 -> SetPointColor(...)
« Reply #3 on: February 24, 2012, 08:13:35 pm »
Don't say it's not easy without trying it first ;)

What kind of shapes do you need? Only rectangles?
Laurent Gomila - SFML developer

Orezar

  • Newbie
  • *
  • Posts: 38
    • View Profile
SFML 2.0 -> SetPointColor(...)
« Reply #4 on: February 25, 2012, 08:22:34 am »
Yes, only for Rectangle...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 -> SetPointColor(...)
« Reply #5 on: February 25, 2012, 09:29:50 am »
So it's even easier, you only have 4 vertices to define, no extra computation is needed.

Do you also need texturing and position/rotation/scale?
Laurent Gomila - SFML developer

Orezar

  • Newbie
  • *
  • Posts: 38
    • View Profile
SFML 2.0 -> SetPointColor(...)
« Reply #6 on: February 25, 2012, 09:40:14 am »
Yes, I need position and maybe rotation, texture not necessarily...
So I need 4 Vertices Objects one Vertices Array and one RectangleShape?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 -> SetPointColor(...)
« Reply #7 on: February 25, 2012, 09:54:06 am »
You can do this:
Code: [Select]
class MyRectangle : public sf::Drawable, public sf::Transformable
{
public:

    void SetPointPosition(unsigned int i, const sf::Vector2f& position)
    {
        myVertices[i].Position = position;
    }

    void SetPointColor(unsigned int i, const sf::Color& color)
    {
        myVertices[i].Color = color;
    }

    ...

private:

    virtual void Draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
        states.Transform *= GetTransform();
        target.Draw(myVertices, 4, sf::Quads, states);
    }

    sf::Vertex myVertices[4];
};

MyRectangle rect;
rect.SetPointPosition(...);
rect.SetPointColor(...);
...
window.Draw(rect);
Laurent Gomila - SFML developer

Orezar

  • Newbie
  • *
  • Posts: 38
    • View Profile
SFML 2.0 -> SetPointColor(...)
« Reply #8 on: February 26, 2012, 11:02:30 am »
Thanks. Works perfectly :)

But I have still another problem, its because moving, how
can I make a function like GetFrameTime()?

Must I make a Clock Object that Restarts every Time the
Game Loop ends?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
SFML 2.0 -> SetPointColor(...)
« Reply #9 on: February 26, 2012, 11:08:54 am »
Yes, you have to use a clock.
Code: [Select]
sf::Clock frameClock;
for (;;)
{
    // ...
    const sf::Time frameTime = frameClock.Restart();
}
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 -> SetPointColor(...)
« Reply #10 on: February 26, 2012, 11:10:30 am »
Quote
Must I make a Clock Object that Restarts every Time the
Game Loop ends?

Yes, you can do this.
Laurent Gomila - SFML developer

Orezar

  • Newbie
  • *
  • Posts: 38
    • View Profile
SFML 2.0 -> SetPointColor(...)
« Reply #11 on: February 26, 2012, 11:19:04 am »
Ok, thanks. Can I ask why the GetFrameTime() Function was
kicked out from the Libary, I mean what is the Reason?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 -> SetPointColor(...)
« Reply #12 on: February 26, 2012, 12:13:16 pm »
Laurent Gomila - SFML developer

Mikademus

  • Newbie
  • *
  • Posts: 31
    • View Profile
SFML 2.0 -> SetPointColor(...)
« Reply #13 on: February 27, 2012, 10:34:21 am »
Very nice reply with the source code, Laurent. Might I suggest using this as example code in the wiki (is there a wiki?), perhaps an "making custom shape classes" article or something similar? I predict this question will arise quite a few times more.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 -> SetPointColor(...)
« Reply #14 on: February 27, 2012, 10:45:49 am »
Could be a good idea (yes, there is a wiki ;)). But we should wait until SFML 2.0 is released, and we get more feedback, so that we can really see what kind of examples people need.

Maybe I'll cover this area in the tutorials as well.
Laurent Gomila - SFML developer

 

anything