Hello, I'm trying to load a texture and a sprite. This works fine as long as I define them inside my .cpp file, but if I move the texture to the header file nothing is shown in the window.
Here is the header file:
#pragma once
#include <SFML/Graphics.hpp>
using namespace sf;
class GameObject
{
public:
GameObject();
~GameObject();
void Draw(RenderWindow *);
void Update();
Sprite sprite;
Texture texture;
};
This is the .cpp file:
GameObject::GameObject()
{
if (!texture.loadFromFile("sprite.png"))
{
}
sprite.setTexture(texture);
}
void GameObject::Draw(RenderWindow * window)
{
window->draw(GameObject::sprite);
}
I tried debugging it at it looks like my texture doesn't have a y size when its defined inside the header. Why is that?
Note: I'm a C# programmer who is trying to play around with C++, there might be some things, that I dont understand yet.