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

Pages: [1]
1
General / sf::Mouse mouse; gives an error
« on: May 15, 2023, 07:56:30 pm »
Currently, I'm using SFML 3.0.0 and it seems that I can't do
sf::Mouse mouse;

anymore, does this mean any time I want to call a method such as mouse.getPosition() I will need to call sf::Mouse::getPosition() instead?

Is there any alternative?

Thanks!

2
so I'm using sf::Close to get some delta time in my program (its for having a server timeout connections after x seconds)

It's something like this:

    float timeout = 0;
    sf::Clock deltaClock;
    while (true){
        sf::Time dt = deltaClock.restart();
        timeout += dt.asSeconds();

        if(timeout > 1){
            std::cout << "should kick player now\n";
        }
 }




except for the std::cout never gets called...

EXCEPT when I have the tick take a lot longer (I just calculate a couple of thousand square roots) and then it works perfectly.

Maybe the sf::Clock module doesn't work well with VERY small numbers? But I tried using milliseconds and microseconds (which should be bigger) but no difference.

not sure what to do.

BTW there's no GUI I'm just using SFML for the network module and the clock module.

3
Network / sf::IpAddress doesn't except a std::string. M2
« on: December 24, 2022, 02:30:45 am »
I recently got SFML working on my m2 MacBook and everything is fine except for sf::IpAddres, there isn't an option to pass in a string as an option.

Here's the error:
No matching constructor for initialization of 'sf::IpAddress'

The frameworks I used were the snapshot macos-clang-arm64.tar.gz, Date: 2022-Dec-22 16:39

I think that the snapshots might be the problem, but I'm not sure.

Btw here's the code I used:

#include <SFML/Network.hpp>

sf::TcpSocket socket;
void connect(std::string IPaddress){
    sf::IpAddress address(IPaddress);
}
 


Edit:
turns out I just needed to use sf::IpAddress::resolve(std::string); instead, problem solved :D.



4
General discussions / Setting up SFML Xcode on M1 or M2
« on: December 17, 2022, 08:03:43 pm »
This is a post that goes over how I set up SFML on my M2 MacBook pro running Ventura 13.0.1 and got it working on Xcode version 14.0.1.

I spent a week combing through videos and forum posts trying to figure this out so this post should hopefully help others not to have to waste as much time as I did XD.

To start off, make sure to download Xcode. I downloaded it from AppStore. so should be pretty easy for you to do. (if you can't figure out how to download something from the AppStore... welp)

Next, we want to download SFML, currently, the main version of SFML, WILL NOT work on your M1 or M2 mac so we want to use one of the snapshot versions.
This can be done by going to the SFML website, clicking "download" then selecting "snapshots", (or go to this link: https://artifacts.sfml-dev.org/by-branch/master/)
Now the snapshot I downloaded was the "macos-clang-arm64.tar.gz" (make sure it's arm64).

Now copy all the .framework folders you downloaded (it's a couple of folders deep) into "Library/Frameworks/"

(if you struggling to find "Library/Frameworks/" open a finder window and press "command"+"," the sidebar, then check the "Hard Disks" option, now your root folder should appear on your sidebar in finder)

Your frameworks folder (in "Library/Frameworks") should look like the image I have attached.
You might have other framework files like a python one or whatnot but that's COMPLETELY FINE, DON'T DELETE any of the files that were already in the folder.

Next open Xcode and create a new terminal application (I am not using the SFML templates for this example, I couldn't get them working so just an empty project)

Open up Xcode project options and go to the "general" tab, under "frameworks and libraries" click the little "+" and under "add other", click "add files..." now locate the "Library/Frameworks" folder and select the following options:
sfml-graphics.framework
sfml-system.framework
sfml-window.framework

once you've done that, go to the "Build Phases" tab and under "Link Binary with Libraries" do the same thing.

now go to the main.cpp file and copy the following test code into it:

#include <SFML/Graphics.hpp>

int main(int argc, const char * argv[]) {
   
    sf::RenderWindow window(sf::VideoMode(sf::Vector2u(200, 200)), "Title");
   
    sf::RectangleShape rect;
    rect.setSize(sf::Vector2f(100, 100));
    rect.setFillColor(sf::Color::Red);
    rect.setPosition(sf::Vector2f(50, 50));

   
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if(event.type == sf::Event::Closed)
                window.close();
        }
       
        window.clear();
        window.draw(rect);
        window.display();
    }
}


Now run the program, if it's working you should get a popup error that says something along the lines of "sfml-graphics.framework is broken and can't be run" if you get this pop-up then do the following:

open up a new terminal window, paste the command "cd /Library/Frameworks " and you should get routed into the frameworks folder.

What the error means is that your computer is blocking the frameworks form running for security, so we want to tell the computer that it's allowed to run. (btw you can check the framework by running "ls -l@ <framework name>") to allow each framework we want to run the command

"sudo xattr -d com.apple.quarantine <name of framework>"

where <name of framework> is one of the folders (e.g. sfml-graphics.framework or sfml-window.framework)

now you want to do this command for every framework you copied over, it might take a bit but once you've finished you should be able to run the program and see a window pop up with a red square in it.

That's how I got this working, if you have any suggestions on how this post could be made better or if you want to expand on how to use the templates please do.

5
General / Build for Mac OS from windows 10 machine
« on: March 30, 2022, 05:08:38 pm »
I'm a Windows 10 user, and I use my pc (again windows 10) but my family all use macs, (I don't own one) but I want to share my projects with them, I'd like to know if there are any resources which allow me to build a project on my windows 10 pc and then send it to a Mac computer and have it work.

I've looked around on the internet for a while but I mostly found things like "How to build sfml from mac" which isn't very helpful, I understand that this might not be possible at all which would be disappointing xD.

Thanks in advance.

6
Network / sf::IpAddress::Broadcast returns wrong ip address
« on: March 29, 2022, 09:02:35 pm »
so I'm making a local multiplayer game that allows a server and client to see each other by broadcasting a UDP message from the server every second with some information, such as the name of the game, IP of the host, number of players, etc. I was using sf::IpAddress::Broadcast but it returns 255.255.255.255 with works on localhost, but other people in the LAN didn't receive any messages.

I read https://serverfault.com/questions/219764/255-255-255-255-vs-192-168-1-255 and so instead of using sf::IpAddress::Broadcast, I changed it to 192.168.1.255, and it works perfectly, I understand that this wouldn't work on all networks as they would have different network addresses, but I'm just wondering why sfml returns an IP that doesn't work on the LAN.

This might be a problem only for me, I'm not sure but any help or information about it would be appreciated.

7
General / Re: event.text.unicode returning wrong code
« on: March 22, 2022, 10:24:37 pm »
Worked like a charm, thanks so much. :D
 :)  :)  :)  :)  :)

8
General / event.text.unicode returning wrong code
« on: March 22, 2022, 06:43:24 pm »
I'm making a widgets class for some of my projects and I've implemented buttons, sliders, switches, etc, but having a problem with the input field, currently, I'm just trying to get whatever character I'm typing to print in console, but it seems like either, event.text.unicode, my computer, or my conversion method is wrong because I'm getting an output, but it's not the expected one.

here's the code. (taken directly from sfml events page, https://www.sfml-dev.org/tutorials/2.5/window-events.php)


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

            if (event.type == sf::Event::KeyPressed)
            {
            if (event.text.unicode < 128)
            std::cout << "event.text.unicode = " << event.text.unicode <<  ". ASCII character returned: " <<
            static_cast<char>(event.text.unicode) << std::endl;
            }
        }

here's the output when I click different keys:

(clicks "a" key)
event.text.unicode = 0. ASCII character returned:

(clicks "g" key)
event.text.unicode = 6. ASCII character returned: 

(clicks "1" key)
event.text.unicode = 27. ASCII character returned:

(clicks "7" key)
vent.text.unicode = 33. ASCII character returned: !
(that missing "e" at the start is actually there)

(clicks "9" key)
event.text.unicode = 35. ASCII character returned: #


these are very unexpected and I don't know what to do, I looked up a Unicode char on Wikipedia https://en.wikipedia.org/wiki/List_of_Unicode_characters but it didn't give me much info, any help would be appreciated thanks in advance.

Pages: [1]