SFML LoadFromFile doesnt wok

-1

!!!!SUCCESS!!!! Okay so I'm really happy, I finally found an answer to this...So the console showed out so many character and stuff because I was not using the Active(debug) configuration and not the sfml-graphics-d.lib and other, and the dlls ofcource.. well I finally got it out on the screen

I'm trying to add a sprite in my game and so I write the typical code and I even tried to change the working directory but where ever I place the .png file or with the folders the console goes crazy and the SFML screen goes white.

Here the code is but I have other header files but they don't have anything to do with the sprite:

#include <SFML/Graphics.hpp>

#include "Variables.h"
#include "Player.h"

void Update();
void Render();

int main()
{
    Render();
    return 0;
}

void Render()
{
    Variables v;
    Player player;


    sf::RenderWindow window(sf::VideoMode(v.WIDTH, v.HEIGHT), "SFML works!");

    sf::Texture PlayerT;
    PlayerT.loadFromFile("Sprites/Player/player.png");
    sf::Sprite PlayerSprite(PlayerT);


    sf::RectangleShape Player;
    Player.setSize(sf::Vector2f(player.Pw, player.Ph));
    Player.setPosition(player.Px, player.Py);
    Player.setFillColor(sf::Color::Red);


    while (window.isOpen())
    {
        player.PlayerCanMove = true;
        player.PlayerDraw = true;

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))    //if    Right arrow pressed move to the Right
            player.Px += player.Ps;

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))     //if Left arrow pressed move to the Left
            player.Px -= player.Ps;

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))       //if Up arrow pressed move to Up
            player.Py -= player.Ps;

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))     //if Down arrow pressed move to Down
            player.Py += player.Ps;

            /////////////////////       collision check         ////////////////////////////////////

        if (player.Py + player.Ph > v.HEIGHT)
        {
            player.Py -= player.Ps;
        }else if (player.Py < 0)
            player.Py += player.Ps;

        if(player.Px < 0)
        {
            player.Px += player.Ps;
        }
        else if (player.Px + player.Pw > v.WIDTH)
            player.Px -= player.Ps;



        /////////////////////       collision check     ////////////////////////////////////


        ///////// Set the movement of any movable object ////////

        if(player.PlayerCanMove != false)                //If Player shouldnt be able to move, we wont allow it to move
            Player.setPosition(player.Px, player.Py);


        sf::Event event;

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

        window.clear(sf::Color::Black);

        if(player.PlayerDraw != false)              //If Player shouldnt be drawn, we wont allow the program to do so
            window.draw(Player);

        window.draw(PlayerSprite);

        window.display();
    }
}

EDIT: The code gives out this error (I use visual studio)

Exception thrown at 0x5721E310 (vcruntime140.dll) in Project3.exe: 0xC0000005: Access violation reading location 0x059F7000.

I still can't understand what the problem is though.

EDID 2: I made another program to test it again and its not a BUG IN MY CODE, I checked the messy stuff the console took out and I found that it says

Failed to load image "`â•‘player.png

which is a bit I don't know but I typed t.LoadFromFile("player.png");

and I placed the picture everywhere in every folder but I still got the same error.

EDID 3: I even tried to show to full path to the image but I get the same error

c++
sfml
asked on Stack Overflow Sep 12, 2018 by xX randomryze Xx • edited Sep 12, 2018 by xX randomryze Xx

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0