Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Entity System Not Working Right  (Read 1192 times)

0 Members and 1 Guest are viewing this topic.

Paki Programmer

  • Newbie
  • *
  • Posts: 31
    • View Profile
Entity System Not Working Right
« on: February 06, 2012, 11:18:43 pm »
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

Code: [Select]


#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

Code: [Select]


#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

Code: [Select]


#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;
}


Paki Programmer

  • Newbie
  • *
  • Posts: 31
    • View Profile
Entity System Not Working Right
« Reply #1 on: February 07, 2012, 12:26:59 am »
Never mind guys...i fixed it :) just had to make some pointers

 

anything