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.


Topics - DasOhmoff

Pages: [1]
1
General / Update origin in sprite before rendering?
« on: September 01, 2015, 06:24:57 pm »
Hi,

just wanted to ask if there is a way to update the origin of the sprite before drawing it.

This is not possible:
sf::FloatRect gb = sprite.getGlobalBounds();
sprite.setOrigin(gb.width / 2, gb.height / 2);
sprite.rotate(90);
sprite.setOrigin(0, 0);
 

I setted the origin to the center and rotated it but the rotation point is not in the center.
It rotates aroung the point 0, 0.
I think the code would work if the origin would not be updated when the sprite is drawen.

I NEED the origin to be at 0, 0 but I also want the sprite to rotate from in the center...

Is there a way to do it?

2
Graphics / sf::Texture and sf::Sprite not working with std::tuple
« on: August 20, 2015, 11:07:49 pm »
Hi, I have a problem and I can not solve it...

Code: [Select]
#include <SFML/Graphics.hpp>

#include <iostream>
#include <vector>
#include <tuple>

enum class ID
{
Background,
Player
};

std::vector<std::tuple<ID, sf::Texture, sf::Sprite>> drawables;

void add(ID id, const std::string &path)
{
sf::Texture texture;
if(!texture.loadFromFile(path))
throw std::runtime_error("Could not load: " + path);

sf::Sprite sprite(texture);

drawables.push_back(std::make_tuple(id,texture,sprite));
}

int main()
{
add(ID::Background, "Data/Background.png");

sf::RenderWindow window(sf::VideoMode(500, 500), "Test");
window.setFramerateLimit(60);

while(window.isOpen())
{
window.clear();
window.draw(std::get<2>(drawables[0]));
window.display();
}

return 0;
}

I really don't get why this is not working, I think that the texture or sprite is somewhere copied and not used as a reference but i can not change the vector's tuple arguments to references or pointers because this makes errors :/

3
General / [SOLVED] SFML sf::Transform combined transforms
« on: June 21, 2015, 08:50:46 pm »
Hello,

i am trying to understand the meaning of

" Overload of binary operator * to combine two transforms. This call is equivalent to calling Transform(left).combine(right). "

but I can't understand this. I am reading the book "SFML Game Development" and I reached this part where I have to wirte this:

HPP FILE:
class SceneNode : public sf::Transformable, public sf::Drawable, private sf::NonCopyable
{
    ...

    private:
        sf::Transform getWorldTransform() const;

        SceneNode *mParent;
       
    ...
};


CPP FILE:
sf::Transform SceneNode::getWorldTransform() const
{
    sf::Transform transform = sf::Transform::Identity;

    for (const SceneNode* node = this; node != nullptr; node = node->mParent)
        transform = node->getTransform() * transform;

    return transform;
}

If a SceneNode is a child, it means it has a parent, we store it in mParent, we have a function which attaches children.
I understand what we are trying to do here, but I don't understand why this for loop should give us the complete transform of the world. We are multiplying our transform with the one our parent has, and if our parent has a parent too, we are multiplying transform with it either and so on. But why should this give us the complete world transform?

For example our position is (50, 50), position of our parent is (10, 10).
So transform * child-transform is (500, 500). Is this our world transform???

I don't get it, I'm sorry, I'm to stupid for that. What is the purpose of '*' operator?


4
General / Qt creator can't find Image.
« on: March 13, 2015, 09:29:13 pm »
Hi,

I wrote this code:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow sf_window(sf::VideoMode(1280, 720, 32), "Test");
    sf::Event        sf_event;

    sf::Texture sf_texture;
    sf_texture.loadFromFile("Background.png");

    sf::Sprite sf_sprite(sf_texture);

    while(sf_window.isOpen())
    {
        while(sf_window.pollEvent(sf_event))
            if(sf_event.type == sf::Event::Closed)
                sf_window.close();

        sf_window.clear();
        sf_window.draw(sf_sprite);
        sf_window.display();
    }

    return 0;
}
 

I can compile and start the program, it tells me that sfml can’t open the file.
I tested it with g++ on my Linux and it worked perfectly, and because of that I think that I do something wrong with the path of the picture.

The image is in the location of the .pro file (Project file) and i think that qt creator should be able to find it.

5
Hello :D,

I just wanted to know if there are good or "professional" SFML games.
Because i searched with Google but online found some hobby games from diffrent hobby programmers.

I want to create a game and then sell it for a bit pocket money.
But is this posible with SFML or is there a better alternate for SFML?

I dont want to leave SFML because it has graphics, audio, network... and it's easy to use :D , so should I give a try?

PS: Sry for my englisch xD

6
General / Codeblocks portable SFML Problem
« on: June 13, 2013, 08:27:24 pm »
Hi, (I had this post already in the "SFML Projekts" layer or what ever this is called)

I have a SFML Problem, I want to programm with sfml in Codeblocks but it isn't working.

I've downloaded the GCC 4.7 TDM (SJLJ) - 64 bits and I've *past tense of read*  how to install ,

but is still not working. I don't realy like Codeblocks, I have Visual C++

and it is working. I only use Codeblocks on other Computer because its portable, I use it on my

USB Stick.


The Code:

#include <iostream>
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow Window(sf::VideoMode(800,600), "My Game!");
    Window.setFramerateLimit(15);

    while(Window.isOpen())
    {

    }

    Window.clear();
    Window.display();
}


The Error:

-------------- Build: Debug in Mein CB Projekt ---------------

mingw32-g++.exe -L..\..\SFML-2.0\lib  -o "bin\Debug\Mein CB Projekt.exe" obj\Debug\main.o    ..\..\SFML-2.0\lib\libsfml-graphics-d.a ..\..\SFML-2.0\lib\libsfml-window-d.a ..\..\SFML-2.0\lib\libsfml-system-d.a ..\..\SFML-2.0\lib\libsfml-main-d.a ..\..\SFML-2.0\lib\libsfml-audio-d.a ..\..\SFML-2.0\lib\libsfml-network-d.a
obj\Debug\main.o: In function `main':
J:/CodeBlocks-EP/Meine Projekte/Mein CB Projekt/main.cpp:6: undefined reference to `sf::String::String(char const*, std::locale const&)'
J:/CodeBlocks-EP/Meine Projekte/Mein CB Projekt/main.cpp:6: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
J:/CodeBlocks-EP/Meine Projekte/Mein CB Projekt/main.cpp:6: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
J:/CodeBlocks-EP/Meine Projekte/Mein CB Projekt/main.cpp:6: undefined reference to `sf::RenderWindow::~RenderWindow()'
J:/CodeBlocks-EP/Meine Projekte/Mein CB Projekt/main.cpp:7: undefined reference to `sf::Window::setFramerateLimit(unsigned int)'
J:/CodeBlocks-EP/Meine Projekte/Mein CB Projekt/main.cpp:9: undefined reference to `sf::Window::isOpen() const'
J:/CodeBlocks-EP/Meine Projekte/Mein CB Projekt/main.cpp:14: undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
J:/CodeBlocks-EP/Meine Projekte/Mein CB Projekt/main.cpp:14: undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
J:/CodeBlocks-EP/Meine Projekte/Mein CB Projekt/main.cpp:15: undefined reference to `sf::Window::display()'
J:/CodeBlocks-EP/Meine Projekte/Mein CB Projekt/main.cpp:15: undefined reference to `sf::RenderWindow::~RenderWindow()'
J:/CodeBlocks-EP/Meine Projekte/Mein CB Projekt/main.cpp:15: undefined reference to `sf::RenderWindow::~RenderWindow()'
Process terminated with status 1 (0 minutes, 2 seconds)
11 errors, 0 warnings (0 minutes, 2 seconds)
 

Pls help me

PS: SRY for my English im in the 8 Class

Pages: [1]
anything