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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - yannik

Pages: [1]
1
Graphics / Re: Overriding sf::RectangleShape::draw
« on: April 16, 2017, 07:45:49 pm »
But then I have another question: If I now want to change the outline thickness or color of the Square, do I have to call RectangleShape::update afterwards? If so, how can I call a protected function from this context? I tried changing the color, but the Square doesn't change, and I can't call update because it's protected (which is actually why I derived from it in the first place  :D)

2
Graphics / Re: Overriding sf::RectangleShape::draw
« on: April 16, 2017, 03:09:31 pm »
Ah okay, didn't know that. Thank you :)

3
Graphics / Re: Overriding sf::RectangleShape::draw
« on: April 16, 2017, 01:46:21 pm »
Hm, okay. I just thought a square is a rectangle and doesn't just own one, and should therefore be derived from it.

4
Graphics / Overriding sf::RectangleShape::draw
« on: April 16, 2017, 12:52:43 pm »
Hello,
I derive a class Square from RectangleShape. The Square also contains a text I want to draw. But when I override draw to draw the text, how do I also draw the rectangle? Do I have to create yet another class or is there something I'm missing? Here's the code

#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/RenderWindow.hpp>

#include <string>

class Square : public sf::RectangleShape
{
private:
    sf::Text            mText;

public:
                                Square(const sf::Font& font, sf::Vector2f position, const std::string& s = "");

    void                        update();

private:
    void                        draw(sf::RenderTarget& target, sf::RenderStates states) const;
};

Square::Square(const sf::Font& font, sf::Vector2f position, const std::string& s)
{
        mText.setFont(font);
        mText.setString(s);
        mText.setCharacterSize(26);
        mText.setFillColor(sf::Color::White);
        mText.setPosition(sf::Vector2f(position.x + 16, position.y + 8));

        setPosition(position);
        setSize(sf::Vector2f(48, 48));
        setFillColor(sf::Color::Transparent);
        setOutlineColor(sf::Color::White);
        setOutlineThickness(1.3f);
}

void Square::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
        target.draw(mText);
}

void Square::update()
{
        RectangleShape::update();
}

int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480), "");
        sf::Font font;
        font.loadFromFile("arial.ttf");
        Square square(font, sf::Vector2f(10, 10), "A");
        while(window.isOpen())
        {
                window.clear();
                square.update();
                window.draw(square);
                window.display();
        }
}
 

Thanks in advance.

5
General discussions / SFML Game Development review
« on: April 03, 2017, 02:13:04 pm »
Hello,
I had no prior experience with SFML and wanted to learn how to write games with C++, so I bought "SFML Game Development". I'm currently at chapter 9 and have noticed a few things I'd like to say.
First of all, the price. It's quite expensive, and comparing it to other books in the genre (like this german c++ book) I expect more detail when it comes to explaining how to get the software running. The aforementioned book costs less, is three times the size and includes not only a CD with an automated installer, but also detailed tutorials about how to set the IDE, compiler and even some libraries like boost or Qt up. "I'm sorry we can't tell you how to do this, but I'm sure you'll find some tutorials on the internet" just doesn't cut it.
Concerning the content, I really appreciate the modern C++11 style and code-design and the relatively detailed explanations in the first three chapters. But later on, explanations become more and more superficial and leave much to be desired - for example on page 116, where the "StateStack" is covered. Many times, it's explained WHY we need something, but not just how all of this works together and why something's designed this particular way. Like "To do this, we need this class: " (A lot of code.) Understood? Great. Now we implement it. And while it's explained how to use a factory to create states, I'm left wondering which class needs a StateStack. The world or the application class? Or is the application a statestack? Same goes for the Context structure, I want to know which classes need one and why. I need diagrams and pictures showing me where all the classes fit in and work hand in hand. Even after copying every single line of code I still had a lot of questions and couldn't even get the damn thing to run, it was just too much input and too little explanation.
Lastly, I bought this book so I could learn the basics about game programming. In my opinion, saying "we can't tell you anything at all about GLSL because it's too complicated", "Steering behaviors are very interesting. Don't hesitate to search the internet" or "Separating Axis Theorom is a popular algorithm, read more about it here: ..." collides with the purpose of this book. Why not even try to explain at least a little bit? I bought the book so I could learn about this. I don't need a full explanation, just the basics and a few examples would suffice. I don't know the first thing about GLSL, but the .frag files enclosed are just a few lines long and don't look too complicated.
I hope this doesn't look too much like some lampoon, I wouldn't read the book if I didn't like it. And I'll see how much I've learned when I try to implement some of my own ideas..

Pages: [1]
anything