So I am starting on doing some class stuff with SFML problem is, my sprite doesnt seem to be drawing correctly, can anyone see any errors with my code?
Player.h
#pragma once
#include "Game.h"
class Player
{
public:
Player();
~Player();
void Draw(sf::RenderWindow &window);
int playerSpeed = 1;
private:
sf::Texture playerTexture;
sf::Sprite playerImage;
};
Player.cpp
#include "Player.h"
Player::Player()
{
if (!playerTexture.loadFromFile("images/player.png"))
{
std::cout << "Can't load the player image";
}
playerImage.setTexture(playerTexture);
playerImage.setPosition(200, 200);
}
Player::~Player()
{
}
void Player::Draw(sf::RenderWindow &window){
window.draw(playerImage);
std::cout << "DRAWN";
}
Game.cpp
#include "Game.h"
Game::Game()
{
}
Game::~Game()
{
}
void Game::Setup(){
}
void Game::Update(sf::RenderWindow &window){
//std::cout << "TEST";
Setup();
Draw(window);
}
void Game::Draw(sf::RenderWindow &window){
Player player;
player.Draw(window);
}
main.cpp
#include <SFML/Graphics.hpp>
#include "Game.h"
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
Game game;
game.Update(window);
window.clear();
window.display();
}
return 0;
}
It prints "DRAWN" fine, just doesnt seem to draw the image :/