I'm making a small SFML game called skelton town. (not skeleton (its a inside reference)) I have made a file called Player which i want to allow me to make the player, draw him and allow me to input the keyboard inputs for his movement. but when i include the header to allow me use the file in main nothing is drawn. But i get no actual errors. Can you guys help?
Main#include<SFML/Graphics.hpp>
#include<iostream>
#include<SFML/Window/Keyboard.hpp>
#include "Player.h"
#include <cstdlib>
int main()
{
sf::RenderWindow Window;
Window.create(sf::VideoMode(1920, 1080), "Skelton Town", sf::Style::Fullscreen);
Player player;
while(Window.isOpen())
{
sf::Event Event;
while(Window.pollEvent(Event))
{
switch(Event.type)
{
case sf::Event::Closed:
Window.close();
break;
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
return 0;
}
Window.clear();
Window.draw(player.getSprite()); // Key line here
Window.display();
}
}
Player.cpp#include "Player.h"
#include<iostream>
#include<SFML/Graphics.hpp>
Player::Player()
{
sf::Texture pTexture;
sf::Sprite playerImage;
if(!pTexture.loadFromFile("Player.png",sf::IntRect(30,0,64,32)))
std::cout<<"Error could not load player image"<<std::endl;
playerImage.setTexture(pTexture);
}
Player.h#ifndef PLAYER_H
#define PLAYER_H
#include<SFML/Graphics.hpp>
class Player
{
public:
Player();
sf::Sprite& getSprite() {return playerImage;}
private:
sf::Texture pTexture;
sf::Sprite playerImage;
};
#endif // PLAYER_H
Can Someone Help Me. And Tell me what i have done wrong.