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 - Unistyle

Pages: [1]
1
Graphics / Re: SFML 2: Function return "sf::Sprite" Value
« on: August 05, 2012, 05:47:47 pm »
Quote
You definitely have some issue with classes/objects. sf::Sprite is a class and any class is ONE type. So you can return an object of type sf::Sprite like you would do with a std::string or an int.

Yes, thanks for your answer :)
I just started too fast after my break with C++.
I began to learn all basics again, and now i dont have problems anymore with it :)

2
Graphics / Re: SFML 2: Function return "sf::Sprite" Value
« on: July 25, 2012, 10:59:39 pm »
Thank you for your answer [=
And I'm really sorry for these mistakes ...
I corrected the code in the first post as much as i could.

Quote
You should probably start some good books (e.g. Accelerated C++) or online tutorials to get some strong basis before going on.

I watched Videos to learn how to use OOP in a console. I already learned C++ many times in the past (console over and over again after some breaks :D) This time i directly tried to use it with SFML. Maybe i watch a whole Totorial series the next days. In any case i buy a book :p

Quote
First, in RGB, «G» doesn't stand for «Gelb» but for «Green»; i.e. not yellow.  ;)
I searched for it 1000 times in my life, but this time i didnt searched and write it wrong.
I feel bad^^

Quote
ypos, c_red, ... all need a type
I don't believe i forgot that ... i have to make more breaks and look more often where mistakes are before I open a new Thread.

Quote
your function's return type is void but you try to return something.
Thats the point where i dont know what type i should use. I know how to return ONE type.
But sf::Sprite has not just one type implemented or? I read that you can just return one type,
so is it possible to make my function working? Or do i have to work it another way?

Quote
You forgot to include your header in main, also you have errors there.
Oh i forgot to include it  :-[ Thank you!


~Unistyle~

3
Graphics / [SOLVED] SFML 2: Function return "sf::Sprite" Value
« on: July 25, 2012, 07:00:07 pm »
Hello,

I'm new by using SFML and already searched alot about how to use it.
I stucked by trying to make a function in a class.
Actually it works, ... but it seems to have problems with the return value.

I don't really program long time with c++, so dont slap me when some things could be
very wrong :D
The function "create()" in the class "doSprite" should shorten some things in the "main.cpp"
when i wanna make a sprite. The class isnt finished, but it is ready to test if it works.

Here the code:

doSprite.hpp
#include <SFML/System.hpp>

class doSprite
{
    private:
    public:

        //Member Variablen
        sf::String directory;

        //Position
        int xpos;
        int ypos;

        //Farbe
        int c_red;
        int c_green;
        int c_blue;
        int c_trans;

        //Funktionen
        int create();

        //Konstruktor
        doSprite();

        //Destruktor
        ~doSprite();
};
 

doSprite.cpp
#include "doSprite.hpp"

int doSprite::create(sf::String directory, int xpos, int ypos, int c_red, int c_green, int c_blue, int c_trans)
{
    sf::Texture texturName;
    if(!tx_player.loadFromFile(directory))
        return 1;

    sf::Sprite sprSprite;
    spr_player.setTexture(sprSprite);
    spr_player.setPosition(xpos,ypos);
    spr_player.setColor(sf::Color(c_red,c_green,c_blue,c_trans));

    return sprSprite;
}

//Konstruktor
doSprite::doSprite()
{
    //Member Variablen
    directory = "Sprites/Player/2.png";

    //Position
    xpos = 0;
    ypos = 0;

    //Farbe
    c_red = 255;
    c_green = 255;
    c_blue = 255;
    c_trans = 255;
}

//Destruktor
doSprite::~doSprite()
{

}
 

main.cpp
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include "doSprite.hpp"

int main()
{
    sf::VideoMode VMode = sf::VideoMode::getDesktopMode();
    sf::RenderWindow window(VMode, "SFML works!",sf::Style::Default);

    /* Test Function in class instead of this piece of code :/
    sf::Texture tx_player;
    if(!tx_player.loadFromFile("Sprites/Player/2.png"))
        return 1;

    sf::Sprite spr_player;
    spr_player.setTexture(tx_player);
    spr_player.setPosition(100,100);
    spr_player.setColor(sf::Color(255,255,255,255));
    */

    doSprite dS;
    sf::Sprite spr_player = dS.create("Sprites/Player/2.png", 200, 200, 255, 255, 255, 200);

    // Das Programm läuft solange das Fenster offen ist
    while (window.isOpen())
    {
        // Prüft alle Events, bis alle abgearbeitet sind
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Mit dem "close requested" Event wird das Fenster geschlossen
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear(sf::Color(0,255,255));
        window.draw(spr_player);
        window.display();
    }

    return 0;
}
 

Build Log:
...\main.cpp:20: error: 'doSprite' was not declared in this scope
...\main.cpp:35: error: 'spr_player' was not declared in this scope
 

So the problem is, i dont really know how to return "sprSprite" from the "doSprite.cpp" to "main.cpp".
I hope you can help me :)

Edit: Added Build log under code.



~Unistyle~

Pages: [1]
anything