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

Author Topic: Issue with LoadFromFile  (Read 1534 times)

0 Members and 1 Guest are viewing this topic.

Junalista

  • Newbie
  • *
  • Posts: 5
    • View Profile
Issue with LoadFromFile
« on: January 20, 2024, 03:47:44 pm »
I'm new with sfml, i finished by installing sfml on visual studio 2022 after many tries!
Now i hv tested the code given by the site it fucntionning correctly!
Show windows with the circle!
Now i wanted to test LoadFromFile but it say it has no definition!
So i tried other function has isKeyPressed this one work pefectly
So i dont understand why LoadFromFile not working, i hv tried also SetTexture and i get the same error!
Can someone help me please?


Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Issue with LoadFromFile
« Reply #1 on: January 21, 2024, 05:11:53 pm »
Hi and welcome! :)


More information may be needed to help with this quite specific issue.

Your device set-up details can help as well as which version of SFML you are using etc..

Also, providing the actual error will help, including error codes and surrounding information.

Depending on if it's "not working" during runtime or compilation, call stack information may also be helpful.


One thing to be aware of, first, is that SFML's version has to match the compiler exactly. With VS, however, the latest one should be okay (it's 2022 version anyway!)
That is if you're using pre-build binaries. If you are building yourself, it's likely to match but it must be build correctly to work.

Similarly, the DLL have to match the Configuration. 32- or 64- bit DLLs must be used when building for 32- or 64- bit. Debug DLLs have "-d" on the end of the filename whereas Release DLLs do not. Debug and Release DLLs should match if building with Debug or Release.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Junalista

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Issue with LoadFromFile
« Reply #2 on: January 21, 2024, 08:01:52 pm »
This is the starting code i use to load my png file as u can see loadFromFile is in white color as it cannot find it!
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <string>


sf::Texture spaceshipTexture;

sf::Sprite spaceship;



if (!spaceshipTexture.loadFromFile("spaceship.png")) {
    // Handle error if the texture fails to load
}







int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Shoot&#39;em up game");
    sf::CircleShape shape(100.f);    
    shape.setFillColor(sf::Color::Green);
        while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
            shape.move(-5.0f, 0.0f);
        }

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
            shape.move(5.0f, 0.0f);
        }

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
            shape.move(0.0f, -5.0f);
        }

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
            shape.move(0.0f, 5.0f);
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

if there is a mistake in my code help me pls

i join in attachment screenshot of visual studio

I use the last version of sfml 2.6.1 32bit Visual C++ 17 (2022)
I put sfml inlcude directory in Additional Include Directories from C/C++
I put -d.lib file in debug configuration in Additional Dependencies from linker



« Last Edit: January 21, 2024, 09:50:58 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Issue with LoadFromFile
« Reply #3 on: January 21, 2024, 09:52:24 pm »
You can't write an if statement in the global scope. It needs to be inside main().

You should also not use global texture and sprite variables.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Junalista

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Issue with LoadFromFile
« Reply #4 on: January 22, 2024, 10:59:14 am »
Thx for ur help
It is working now