I'm recently starting to pick up C++ and the SFML library, and I was wondering if I defined a Sprite on a file appropriately called "player.cpp" how would I call it on my main loop located at "main.cpp"?
Here is my code (Be aware that this is SFML 2.0, not 1.6!).
main.cpp
#include "stdafx.h"
#include <SFML/Graphics.hpp>
#include "player.cpp"
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Skylords - Alpha v1");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw();
window.display();
}
return 0;
}
player.cpp
#include "stdafx.h"
#include <SFML/Graphics.hpp>
int playerSprite(){
sf::Texture Texture;
if(!Texture.loadFromFile("player.png")){
return 1;
}
sf::Sprite Sprite;
Sprite.setTexture(Texture);
return 0;
}
Where I need help is in the main.cpp
where it says window.draw();
in my draw code. In that parenthesis, there should be the name of the Sprite that I want to load onto the screen. As far as I've searched, and tried by guessing, I have not succeeded into making that draw function work with my sprite on the other file.
I feel like I'm missing something big, and very obvious (on either files), but then again, every pro was once a newb.