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

Pages: [1] 2
1
Hi,

this is my CMakeLists.txt:

Code: [Select]
add_executable(foo
  main.cpp
)

set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)

target_link_libraries(foo sfml-graphics sfml-audio)

However, I get the following errors (it shows the same error like ten times):
Code: [Select]
-- Found SFML 2.5.1 in X:/msys64/mingw64/lib/cmake/SFML
-- Configuring incomplete, errors occurred!
See also "X:/msys64/home/Programming/cpp/Simulation/build/CMakeFiles/CMakeOutput.log".
CMake Error at X:/msys64/mingw64/lib/cmake/SFML/SFMLConfigDependencies.cmake:38 (set_property):
  set_property could not find TARGET Vorbis.  Perhaps it has not yet been
  created.
Call Stack (most recent call first):
  X:/msys64/mingw64/lib/cmake/SFML/SFMLConfigDependencies.cmake:74 (sfml_bind_dependency)
  X:/msys64/mingw64/lib/cmake/SFML/SFMLConfig.cmake:117 (include)
  src/CMakeLists.txt:6 (find_package)

vorbis is installed in MSYS2 and I can link it as well (libvorbis.a). The package is:
mingw64/mingw-w64-x86_64-libvorbis

I built SFML like so:

Code: [Select]
cmake .. -G"MSYS Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS:BOOL=FALSE -DSFML_USE_STATIC_STD_LIBS:BOOL=TRUE -DCMAKE_INSTALL_PREFIX:PATH=/mingw64/
make -j
make install

And my project like so:
Code: [Select]
mkdir -p build
cd build
cmake .. -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release
make -j

If I edit SFMLConfigDependencies.cmake and remove everything searching for "Vorbis", and manually link the libraries, it works:

Code: [Select]
target_link_libraries(SkyDrive sfml-graphics sfml-audio vorbis vorbisenc vorbisfile ogg)

So I'm just going to assume there is a problem with the CMake config, since CMake can find the required dependencies without problems if I specify them manually (vorbis, vorbisenc, vorbisfile, ogg). Am I missing something?

Thank you!

2
Hi,

I came across something very puzzling while working with sockets. Check out the following example:
   
#include <iostream>

#include <SFML/Network.hpp>

int main()
{
    sf::TcpListener l;
    l.listen(2017);

    sf::TcpSocket sock;
    if (sock.connect(sf::IpAddress::LocalHost, 2017) == sf::Socket::Done)
        std::cout << "Connected!\n";

    if (sock.connect({1,2,3,4}, 2017) == sf::Socket::Done)
        std::cout << "???\n";

    char ch;
    std::cin >> ch;
}
This gives me
Connected!
???

I would very much expect the second call to connect to fail. Can anyone explain what's going on? Is this a bug? I understand that further calls to connect disconnect the socket first, but the second connection should obviously fail.

Edit:
Equally confusing behaviour, I would expect the second call to connect to succeed, yet I get no output:
    sf::TcpListener l;
    l.listen(2017);

    sf::TcpSocket s;
    if (s.connect({1,2,3,4}, 2017, sf::milliseconds(200)) == sf::Socket::Done)
        std::cout << "???\n";

    if (s.connect(sf::IpAddress::LocalHost, 2017) == sf::Socket::Done)
        std::cout << "Connected\n";

    char ch;
    std::cin >> ch;

I'm compiling with mingw-w64 GCC 7.2.0 on Windows 10 with SFML from github master


I'm trying to loop through a range of IpAddresses e.g. 192.168.178.2 - 192.168.178.99 and attempt to connect with the same socket for each address. At first I thought I was making some mistake using multiple threads, but then I tried a small example in a single main().

Edit2:
Calling disconnect seems to work for me to "handle" a failed connection, kind of like this:
   
sf::Uint8 b1{192}, b2{168}, b3{178};
socks.push_back(std::make_unique<sf::TcpSocket>());
for (sf::Uint8 b4 = 2; b4 < 100; ++b4) {
    if (socks.back()->connect({b1,b2,b3,b4}, port, sf::milliseconds(100)) == sf::Socket::Done) {
        chat.queue("Connected");
        socks.push_back(std::make_unique<sf::TcpSocket>());
    } else
        socks.back()->disconnect();
}

3
General / [Solved] Disable SFML error messages
« on: January 02, 2017, 12:56:58 am »
Hi,

how can I stop SFML from writing to my console?  In my case, I would like to handle sf::UdpSocket::bind() failing in my own way by using another Port.  However, SFML always prints an error message to my console, which I do not want in this case.

4
Graphics / HBITMAP --> sf::Texture/sf::Image using ::loadFromMemory
« on: November 27, 2016, 03:03:04 pm »
Hello,

I need a quick hint on how to properly load e.g. an sf::Texture from memory with the loadFromMemory function. Specifically, I am not sure what precisely the function expects (some data and its size - ok - but what data?). The docs state "load from a file in memory" - does this mean I must construct a .bmp file in memory and pass the pointer to the first byte of the entire file + the size of the file to loadFromMemory?

The error:
Failed to load image from memory. Reason: Image not of any known type, or corrupt

How I obtain my HBITMAP:
OpenClipboard(nullptr);
if (!IsClipboardFormatAvailable(CF_BITMAP))
{
    std::cerr << "No Bitmap in clipboard\n";
    return -1;
}
HBITMAP bmp = (HBITMAP)GetClipboardData(CF_BITMAP);
CloseClipboard();

Here is my code, as you can see I cluelessly use GetDIBits, but I don't know how to load the sf::Image properly.

bool SFMLLoadHBitmapAsImage(HBITMAP bitmap, sf::Image image)
{
    HDC deviceContext = GetDC(nullptr);
    if (!deviceContext)
    {
        return false;
    }
   
    //Create BITMAPINFO variable, set size
    BITMAPINFO bmpInfo{};
    bmpInfo.bmiHeader.biSize = sizeof(bmpInfo.bmiHeader);

    //Get the BITMAPINFO structure from the bitmap
    // I believe this populates the BITMAPINFOHEADER portion of BITMAPINFO
    if (!GetDIBits(deviceContext, bitmap, 0, 0, nullptr, &bmpInfo, DIB_RGB_COLORS))
    {
        return false;
    }

    BYTE *pixels = new BYTE[bmpInfo.bmiHeader.biSizeImage];
    bmpInfo.bmiHeader.biCompression = BI_RGB;

    if (!GetDIBits(deviceContext, bitmap, 0, bmpInfo.bmiHeader.biHeight, (LPVOID)pixels, &bmpInfo, DIB_RGB_COLORS))
    {
        return false;
    }

    if (!image->loadFromMemory(?, ?)) // <-- Not sure what goes here
    {
        return false;
    }

    delete[] pixels;
    ReleaseDC(nullptr, deviceContext);
    return true;
}

I pretty much am trying to update the code from here https://www.codeproject.com/tips/527353/load-an-hbitmap-into-sfml-sf-image-container for SFML2.

This feels like an intuitive solution, but it gives said error:
if (!image->loadFromMemory(pixels, bmpInfo.bmiHeader.biSizeImage))
{
    return false;
}
My guess is this is missing something, since the function isn't called loadFromPixels anymore.

I have about 20+ Tabs of msdn open and am actively trying to understand this hot mess of DDBs and DIBs, until then maybe someone shall ease my pain and point me in the right direction. If I find the solution beforehand I'll make sure to update my post.

Kind Regards,
Raincode

5
Network / TCP and handling sf::Socket::Partial
« on: September 01, 2016, 04:21:55 pm »
Hello again,

I read from the online tutorial (http://www.sfml-dev.org/tutorials/2.4/network-socket.php bottom):

Quote
If sf::Socket::Partial is returned, you must make sure to handle the partial send properly or
else data corruption will occur.

When sending sf::Packets, the byte offset is saved within the sf::Packet itself. In this case,
you must make sure to keep attempting to send the exact same unmodified sf::Packet object
over and over until a status other than sf::Socket::Partial is returned.
Constructing a new sf::Packet object and filling it with the same data will not work,
it must be the same object that was previously sent.

Does this mean I should implement something in this style (and yes it doesn't work, that's why I'm here):
EDIT: The code works now, my previous version wasn't working due to my embarrassing lack of C++ knowledge conserning the remove-erase idiom (I thought remove_if would actually erase the elements).
// edited code, was nonsense
class Server {
// ...
private:
    void send(const sf::Packet& packet);
    void handle_outgoing_packets();
// ...
    std::vector<sf::Packet> pending_packets;
};

void Server::send(const sf::Packet& packet)
{
    pending_packets.push_back(packet);
}

void Server::handle_outgoing_packets()
{
    auto iter = std::remove_if(pending_packets.begin(), pending_packets.end(), [this] (auto& p) {
        return clientSocket.send(p) == sf::Socket::Done;
    });
    pending_packets.erase(iter, pending_packets.end());
}
 

I know this doesn't work properly (because my packets are getting stuck in the "queue"). However, I am more interested in the basic notion of such a mechanism to handle sf::Socket::Partial, or can I just "hit send and be done with it", despite what he documentation says.

P.S.: I am using non-blocking sockets and have a server loop. If I forgot any important information please let me know.

Kind Regards,
Raincode

6
Network / [RESOLVED] outgoing UDP Broadcast blocked on one machine
« on: August 30, 2016, 02:56:51 am »
Hello,

I am trying to write a simple LAN Multiplayer for my Battleship game.

I want to broadcast the IP of the server on the LAN, so any client will automagically find the server.

I wrote this ugly "minimal" example.

Note:
    If I run both client and server on either A or B, I receive the IP.
    If I run server on A and client on B I receive the IP.
    However, if I run the server on B and client on A, I don't receive it.

I have tried various inbound/outbound firewall rules and checked my network visibility settings, or however you may call it (I am running windows machines).

I tried a minimal TCP connection example and it connected properly regardless if I ran server/client on A/B machine. Talk about being confused. I also tried sending directly to the IP, instead of broadcasting - still doesn't work.

I would appreciate it if someone could verify my program is OK, and I have to keep looking for the problem with my setup. Perhaps someone has an idea what might be going on, or what else I could try.

#include <iostream>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
int main()
{
    std::cout << "run as server (y/n)? ";
    char answer {};
    std::cin >> answer;

    constexpr unsigned short Port {50000};

    int ticks {};
    sf::UdpSocket socket;
    socket.setBlocking(false);
    bool is_server {answer == 'y'};
    if (!is_server)  {
        socket.bind(Port);
    }
    while (ticks < 50) {
        if (is_server) {
            sf::Packet p;
            if (socket.send(p, sf::IpAddress::Broadcast, Port) == sf::Socket::Done) {
                std::cout << "Broadcasted IP\n";
            }
        }
        else {
            sf::Packet p;
            sf::IpAddress remoteAddr;
            unsigned short remotePort;
            if (socket.receive(p, remoteAddr, remotePort) == sf::Socket::Done) {
                std::cout << "Received IP: " << remoteAddr.toString() << '\n';
            }
        }
        ++ticks;
        sf::sleep(sf::seconds(1));
    }

    char ch {};
    std::cin >> ch;
    return 0;
}
 

Kind Regards,
Raincode

7
Hi dear community,

I have added collision response for a dynamic entity colliding with a static one (at least that's what I spontaneously chose to call them). By static I mean it doesn't move and by dynamic I mean that it can move.

If I run into a static object and let go of the controls, my entity is positioned nicely at the outer bounds of the static once. (for reference see attachment)
However, if I, after colliding with the static object, continue to move towards the static object (which causes the dynamic object to slide btw), the dynamic one is further in than the outside bounds of the static object (for reference see attachment) Once I stop moving, it immediately jumps back to the correct position.

I think this is a bug (in my game of course!), and it rather annoys me. I mean, it still fulfills its purpose as preventing the player from running through a brick wall, but I believe it isn't correct.

I can't figure out what I have to change in my moving/collision response mechanics to solve this problem. I would be very thankful if someone could help me out and give me some hints.

I checked out this thread: http://en.sfml-dev.org/forums/index.php?topic=13766.0 and I really loved the little example program, but I couldn't really use it to fix my problem.

Another question I have, however it is even less related to SFML, is whether my method of collision response is appropriate. I have read quite many blog posts, tutorials and StackOverflow posts, yet frankly I only understood half of them at best, and from what I picked up, my method was once described (except that I don't use a collision normal (yep, don't exactly know what that is either) to determine the axis, but some ugly if-statements). Please consider this a low priority question, if it is not linked to my problem.

Here is the response code (added comments for hopefully clarification):
// pair is a pair of colliding Entities
else if (matches_categories(pair, Category::DynamicBody, Category::StaticBody)) {
            // dynamic as in movable (e.g. a car), static as in non-movable (e.g. a wall)
                        auto& dynamicEnt = static_cast<Entity&>(*pair.first);
                        auto& staticEnt = static_cast<Entity&>(*pair.second);

                        auto dynamicBounds = dynamicEnt.getBoundingRect();
                        auto staticBounds = staticEnt.getBoundingRect();

                        // since the origins are centered, I need additional offset
                        // so setPosition() puts it to the outside of the static Entity
                        const float offset = dynamicBounds.width / 2.f;

                        sf::Vector2f position = dynamicEnt.getPosition();

                        // in some situations the dynamic entity  would jump around (to the corners mostly), adding
                        // this tolerance value fixed the problem
                        float tol = 5;

                        if (bottom(dynamicBounds) > staticBounds.top + tol && dynamicBounds.top < bottom(staticBounds) - tol) {
                // the collision if happening along the X-Achsis
                //     dynamicEnt.setVelocity(0, dynamicEnt.getVelocity().y);
                                if (position.x > staticEnt.getPosition().x)
                // collision happened to the right of the static entity
                                        position.x = right(staticBounds) + offset;
                                else
                                    // collision happened to the left of the static entity
                                        position.x = staticBounds.left - offset;
                        }
                        else if (right(dynamicBounds) > staticBounds.left && dynamicBounds.left < right(staticBounds)) {
                // the collision is happending along the Y-Achsis
                //     dynamicEnt.setVelocity(dynamicEnt.getVelocity().x, 0);
                                if (position.y > staticEnt.getPosition().y)  
               // collision happened at rhe bottom of the static entity
                                        position.y = bottom(staticBounds) + offset;
                                else
                                    // collision happened at the top of the static entity
                                        position.y = staticBounds.top - offset;
                        }
                        dynamicEnt.setPosition(position);
 

My update of the world is something like this (broken down):
update
    set player velocity (handle input)
    handle collisions
    update entities (e.g. move player by player velocity * dt)
    set player velocity to (0, 0)
 

My input handling for movement is done like this (the actual direction is determined by rotation):
if direction Forward
    entity.setVelocity(0, -mech.get_max_speed());
else if direction Backward
    entity.setVelocity(0, mech.get_max_speed());
};
 

I have created a minimal example. I know the positioning isn't perfect from each side, but it illustrates what I have described quite nicely:
#include <SFML/Graphics.hpp>

float right(const sf::FloatRect& rect) {
    return rect.left + rect.width;
}
float bottom(const sf::FloatRect& rect) {
    return rect.top + rect.height;
}

void check_handle_collision(sf::RectangleShape& dynamic,
                            const sf::RectangleShape& stat)  
{
    auto dynamicBounds = dynamic.getGlobalBounds();
    auto staticBounds = stat.getGlobalBounds();
    if(dynamicBounds.intersects(staticBounds)) {
        const float offset = dynamicBounds.width / 2.f;

        sf::Vector2f position = dynamic.getPosition();

        float tol = 2;

        if (bottom(dynamicBounds) > staticBounds.top + tol && dynamicBounds.top < bottom(staticBounds) - tol) {
            if (position.x > stat.getPosition().x)
                position.x = right(staticBounds) + offset;
            else
                position.x = staticBounds.left - offset;
        }
        else if (right(dynamicBounds) > staticBounds.left && dynamicBounds.left < right(staticBounds)) {
            if (position.y > stat.getPosition().y)
                position.y = bottom(staticBounds) + offset;
            else
                position.y = staticBounds.top - offset;
        }
        dynamic.setPosition(position);
    }
}

int main() {
    sf::RenderWindow window(sf::VideoMode(640, 480), "Minimal example");

    sf::RectangleShape dynamic(sf::Vector2f(64, 64));
    dynamic.setFillColor(sf::Color::Transparent);
    dynamic.setOutlineColor(sf::Color::Green);
    dynamic.setOutlineThickness(1);
    dynamic.setOrigin(dynamic.getGlobalBounds().width / 2.f,
                      dynamic.getGlobalBounds().height / 2.f);
    dynamic.setPosition(100, 100);

    sf::RectangleShape stat = dynamic; // short for static
    stat.setOutlineColor(sf::Color::Blue);
    stat.setPosition(sf::Vector2f(window.getSize()) / 2.f);

    sf::Clock clock;
        sf::Time timeSinceLastUpdate = sf::Time::Zero;
    const sf::Time TimePerFrame = sf::seconds(1.f / 60.f);
    const float speed = 200.f;
    sf::Vector2f vel(0, 0);

        while (window.isOpen()) {
                sf::Time dt = clock.restart();
                timeSinceLastUpdate += dt;

                while (timeSinceLastUpdate > TimePerFrame) {
                        timeSinceLastUpdate -= TimePerFrame;
            sf::Vector2f vel(0, 0);

                        sf::Event event;
                        while(window.pollEvent(event)) {
                if(event.type == sf::Event::Closed)
                    window.close();
                        }

                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                            vel.y += -speed;
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                            vel.y += speed;
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                            vel.x += -speed;
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                            vel.x += speed;

                        check_handle_collision(dynamic, stat);

                        dynamic.move(vel * TimePerFrame.asSeconds());
                }

                window.clear();
                window.draw(stat);
                window.draw(dynamic);
                window.display();
        }
}
 

Sorry for the long post, I just really wanted to describe things precisely, and provide sufficient material.

8
System / Adapting the Hitbox to rotation (rotate sf::FloatRect)
« on: May 21, 2015, 02:07:16 pm »
Hi there,

I am currently working with the SFML Game Dev Book, which provides SceneNodes with a getBoundingRect() function:
virtual sf::FloatRect getBoundingRect() const;
I would like to change the function, so that it takes into account the rotation of my SceneNodes in a way, that it rotates the actual rectangle, instead of resizing it to fit  the rotated Sprite. I have included a picture to illustrate.

I think my motive is clear: The overly large hitboxes would likely make the game experience, if I ever get that far, not really great. You percieve the laser missing you (not knowing its hitbox), however, it still hit you. Seems frustrating.

This is what I tried in code, which wasn't very successful. The Rectangles were not rotated, only offset in their position:
// original function body:
return getWorldTransform().transformRect(mSprite.getGlobalBounds());

// my modification
auto rect = getWorldTransform().transformRect(mSprite.getGlobalBounds());
auto transform = sf::Transform();
transform.rotate(getRotation());
return transform.transformRect(rect);
 

I hope someone can explain to me, how to correctly use SFML to achieve what I want, if possible. Again, as far as I understand it, I want to rotate a FloatRect around its center.

From the Docs I read this:
Since SFML doesn't provide support for oriented rectangles,
the result of this function is always an axis-aligned rectangle.
Which means that if the transform contains a rotation,
the bounding rectangle of the transformed rectangle is returned.

Not sure if there is a solution to my problem or I just have to compute bounding boxes differently somehow. But as things seem, I can't achieve what I show in my picture, is that correct?

Raincode

9
Graphics / Designquestion Spinning Card
« on: April 17, 2015, 11:35:21 pm »
Hello dear community,

EDIT: Current solution: Using 1-Dimensional vector. Not sure if it will work all the way through. Maybe should have put more time into library specific design.

I saw the spinning card in the projects forum a while back. Now I have to make a memory game, and I immediately thoght about it, and how cool it would be to use it.

I altered the example and achieved an effec exactly what I want it to look like (with a single card, in a single main function).

However, it becomes much more difficult in an object oriented environment:

I have created a class that uses the spinning card classes "Card". (I also used this in my minimal example).
It manages the 2 spinning cards/sprites and provides a 'flip' and 'update' function and also inherits sf::Drawable.

In my Game class I wanted an array<array<Card, 4>, 6>, representing the memory cards. My Problem: There is no suitable default constructor for Card, because there is none for SpinningCard either. So, the compiler complains, and gives an Error C2512:
error C2512: 'std::array<std::array<Card,4>,6>' : no appropriate default constructor available

I don't know how to solve this Problem. I simply can't initialize the cards before loading the sprites and setting their position.

I hope somebody can give me some tips on how to change my design to make it work.

Raincode

10
General / [SOLVED] Static linking - undefined references
« on: October 18, 2014, 11:26:48 pm »
Hi there,

I have been using SFML for a while now, always linking dynamically. But I want to be able to run my program without copying a bunch of dll's around, also I just wanted to try linking statically in generell.

I have failed at this before, so I decided  to build  sfml from the snapshot source right away.
Worked perfectly. I build Debug as well as Release static libs with Compiler A.

Then I added Compiler A to QtCreator, added a new Kit with Compiler A and made it default.

Then I added the SFML include path to my project.
Then I added the SFML lib path along with -lsfml-system-s-d -lsfml-window-s-d -lsfml-graphics-s-d to my project.
I set the build mode to Debug.
I add #define SFML_STATIC to my config file (though I heard this is standard anyway)
I click build and get a couple dozen of undefined references all looking kind of like this:
... to `_imp__ZN2sf<...>` whereas <...> are some sort of class or function names mixed with numbers

I really don't know why it isn't working. But please don't tell me to link "in the right order", because I have, I even tried it in reversed order -> no change
Also I am running debug libs in debug mode etc.

Compiler is version 4.8.1 from the MinGW package or whatever it is called. If I can give you any additional information which could help solve my problem, please, let me know.

11
General / Loading Game Data with Lua
« on: June 09, 2014, 10:22:00 am »
Hello,

I have the SFML Game Development Book and it says somewhere:
"Nowadays, it is very common to load gameplay information from external resources [...]
One possibility that has recently gained popularity consists of using script languages, most notably Lua [...]"

I am very interested in trying this, I actually already was before reading this, for loading some data like tables or something and also using it to code some game logic.

However, I have no clue what I need to get started, I guess I need a Lua interpreter, which I have now, but which libaries do I need? Is "Lua binding for C++" the correct term? If I know what I need, I can search for tutorials, documentation and stuff online and do it myself, but I am kind of missing a starting point.

Hope someone can help me

Kind Regards,
Raincode

12
Graphics / Rotate Tower towards enemy
« on: May 01, 2014, 04:00:18 pm »
Greetings,

How do I test in an update function whether a sf::Vector2f is in a certain radius around another sf::Vector2f?
As I understand it, calculate the distance between them and check whether it is smaller or equal to the radius? Distance formula d = sqrt( (x2-x1)² + (y2-y1)² ) correct?

I kinda have problems managing all entities/towers etc. though. Say I detect an entity in radius, I still get problems finding/using the entity afterwards, like "Great, which one was it again?"

But then, how do I know how to rotate, so my tower faces a player given the players position and towers position? (I have a graphic which illustrates what I am trying to achieve).

So I have a tower (which has sprite) and a player (which has sprite) and I want to rotate the tower accordingly, while the player is in range (say I could maybe figure this part out by myself).

P.S.:
I have the thor vectorAlgebra2D library at hand, if it helps. Couldn't find a distance function though

Sorry for seeming like a "noob" in video game terms, I try to do as much as possible by myself, but sometimes you just can't get further for some reason

Raincode

13
Graphics / Not your standard move mechanics
« on: April 15, 2014, 06:09:00 pm »
Hello,

I need help (obviously). Usually, when implementing character movemment, as in game character, I did something like, <top> move upwards, <left> move left, ...

However, I want something different now, and I can't figure it out.

I createt an amature, terrible, picture to explain, I hope it is understandable (see attachment)

Does anyone have an idea how to implement such movement (based on arrow keys, wasd)?

Kind Regards
Raincode

14
General / SFGUI with SFML Game
« on: January 01, 2014, 02:31:07 pm »
Hi everyone,

I wonder: How do you "correctly", as in good manner, use SFGUI in a game? I looked at the examples and they all use one big class with the methods and stuff and simply call the run() function in main().

However, I see two problems with this:
A: I can't possbly put my whole code in one class and
B: I'd like to seperate game  code from GUI code, but how can I do this, since the GUI needs an event loop too?
Do I have to check out threads?

Also, is there a way to write callback functions etc. and use SFGUI, without packing everything in one huge class? I don't think it is a really great design...

Kind Regards

15
Graphics / setPosition() for private sprites
« on: November 24, 2013, 06:29:43 pm »
Hey everyone,

can someone please show me how to move two sprites which are private members of a class through a member function? The relation between the position of these two should stay the same. By that I mean, if I have two vertical lines perfectly aligned, after the function call they still should be aligned.

so basically:

class foo
public:
    foo();

    void setPosition( double x, double y );

private:
    sf::Sprite a;
    sf::Sprite b;
 


Kind Regards,
Raincode

Pages: [1] 2
anything