I'm using a vector array since static would be plain stupid but when I staticly add a NPC from a file everything works
-Coordinance gets set
-Spritesheet successfully loads
etc...
Everything is correctly loaded but luigi seems to be a square.......
I'm probably overlooking a very simple problem but I'm quite stuck
Here is my NpcManager.h
Code: Select all
#ifndef NPC_MANAGER_H
#define NPC_MANAGER_H
#include "NPCs.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
namespace Eternal {
class NpcManager {
private:
NpcManager();
static NpcManager *MyManager;
public:
static NpcManager *GetManager();
~NpcManager();
int AddNpc(float x, float y, std::string file);
void RemoveNpc(int npc);
void UpdateManager();
private:
int Top;
std::vector <Eternal::NPC> Npcs;
};
}
#endif
Code: Select all
#include "NPCManager.h"
#include "Primitives.h"
#include "DebugLog.h"
#include "Camera.h"
using namespace Eternal;
NpcManager *NpcManager::MyManager = 0;
NpcManager *NpcManager::GetManager() {
if ( MyManager == 0 ) {
MyManager = new NpcManager;
}
return MyManager;
}
NpcManager::NpcManager() {
Top = 0;
}
NpcManager::~NpcManager() {
}
int NpcManager::AddNpc(float x, float y, std::string file) {
std::ifstream ifile;
NPC npc;
ifile.open( file.c_str() );
std::string texture;
ifile >> texture;
ifile >> npc.Name;
ifile >> npc.SpriteSheet.Crop.w;
ifile >> npc.SpriteSheet.Crop.h;
ifile.close();
npc.SpriteSheet.Load(texture.c_str()); // .......
npc.SpriteSheet.Pos.x = x;
npc.SpriteSheet.Pos.y = y;
npc.SpriteSheet.Pos.w = npc.SpriteSheet.Crop.h;
npc.SpriteSheet.Pos.w = npc.SpriteSheet.Crop.h;
npc.SpriteSheet.SetColor(255,255,255); // openGL ( original texture colors )
Npcs.push_back(npc);
Top++;
return Top - 1;
}
void NpcManager::RemoveNpc(int npc) {
Npcs.erase(Npcs.begin() + npc);
Top--;
}
void NpcManager::UpdateManager() {
Camera *CameraSys = Camera::GetInstance();
for ( int i = 0;i < Top;i++ ) {
CameraSys->RenderSprite( Npcs[i].SpriteSheet );
}
}
If this helps any here is the NPCs file content I allocated it from
Code: Select all
Data/mario.png --SpriteSheet
Luigi --Name
32 -- Width
64 -- Height
1 -- Nothing past this point is getting loaded so I won't go into details
1
1
Data/Scripts/TestScript1.lua
~c999Hello, I've been staticly allocated from a file.