So in the game that I'm working on at the moment, I've encountered a small bug that i can't seem to fix. I set up the beginning of my entity system to keep track of all the objects in the game and update them accordingly. It works fine for now except for the fact that it doesn't render them to the screen as it is suppose to. It renders the white shape of the sprite instead of the actual image with it.
Here's some of the code for it. If you need more let me know and ill post it.
//Entity Manager
#include "Manager.h"
#include "engine.h"
Manager cManager;
void Manager::Update()
{
this -> iter = this -> entities.begin();
Object object;
while (this -> iter != this -> entities.end())
{
object = *iter;
cEngine.cWindow.Draw(object.Sprite);
iter++;
}
}
void Manager::Add(Object object)
{
this -> entities.push_back(object);
}
//Game.cpp
#include "Game.h"
#include "Manager.h"
#include "engine.h"
Game cGame;
void Game::Game_Init()
{
Character player;
player.Create("ball.bmp", 200, 200, 45, 45);
cManager.Add(player);
}
void Game::Game_Run()
{
cEngine.cWindow.Clear();
cManager.Update();
cEngine.cWindow.Display();
}
//Character.pp
#include "Object.h"
#include "engine.h"
int Character::Create(std::string filename, float x, float y, int width, int height)
{
if (!this -> Image.LoadFromFile(filename.c_str()))
{
return 0;
}
this -> Image.CreateMaskFromColor(sf::Color(255, 0, 255));
this -> Sprite.SetImage(this -> Image);
this -> Sprite.Resize(width, height);
this -> Sprite.SetPosition(x, y);
this -> PosX = this -> Sprite.GetPosition().x;
this -> PosY = this -> Sprite.GetPosition().y;
this -> Rect.Left = this -> PosX;
this -> Rect.Top = this -> PosY;
this -> Rect.Width = width;
this -> Rect.Height = height;
return 1;
}