a String that is the name of the object you want to create, and x/y values at where you want them to spawn in screen coordinates. My guess is something is going out of scope.
It begins looping through my 'Type' object (which is a vector of entities), which contains a list of all the different type of Entities, when it finds one that's name is the same as the parameters, it sets the Type object its currently on position and sets it to active and other game specific stuff. I then proceed to push the current Type object into another vector called entity_list. this is the actual vector i use to loop through and draw to screen/Update Logic for.
the problem lies here, because when i use the spawn function, the entity_list.size grows, but all the objects' variables are 0, and it has no image.
now the Type vector works fine, i checked it but when its pushed on the other vector I think it goes out of scope, any suggestions on how to fix this?
here is my spawn function
//Spawn an entity at a locationvoid Entity_Factory::Spawn(string name, float sx, float sy){ //Loop through all of the different entity types we have for(int i = 0; i < Type.size(); i++) { //Iff the name of what we want is the same as //as the current type, spawn it if(Type.Get_Name() == name) { //set position Type.SetPosition(sx, sy); //set state to Active Type.Set_State(ES_ACTIVE); float total_cost = 0; //find its path Pather.SolvePath(sx, sy, Map.pathEnd.x, Map.pathEnd.y, Type.path, total_cost); //Assign image damn it if(Type.img != NULL) { Type.SetImage( *Type.img ); } //Test to see if it worked /* cout << Type.Get_Name().c_str() << endl; cout << Type.Get_State() << endl; cout << Type.GetPosition().x << ", " << Type.GetPosition().y << endl; */ entity_list.push_back(Type);//Testing purposes, All the values are 0 except for Get Name//Which is somehow the name its suppose to be ("chomps") for(int i = 0; i < entity_list.size(); i++ ) { cout << entity_list.Get_Name().c_str() << endl; cout << entity_list.Get_State() << endl; cout << entity_list.GetPosition().x << ", " << entity_list.GetPosition().y << endl<< endl; } //entity_list[0] = Type; //add to the list //entity_list.push_back(Type); cout << entity_list.size() << endl << endl; break; } }}//EoF
And my Entity Managing class
#ifndef _ENTITY_FACTORY_H#define _ENTITY_FACTORY_H#include <SFML/Graphics.hpp>#include <vector>#include "factory.h"#include "entity.h"enum Entity_State{ ES_NONE = 0, ES_ACTIVE, ES_DEAD};//All important Entity system Classclass Entity_Factory : public Factory{public: Entity_Factory(); ~Entity_Factory(); //Spawn an entity by its name at a certain location void Spawn(string, float, float); //Draw all of the Entities void Draw(); //Update all entity Logic void Update_Logic(); std::vector < Entity > Type;private: bool Load_TypeIntoList( string ); //we have a Type //and entity list //all things of the entity list will basicly be an instance //of something from the Type list //tried to use a pointer to a temporary entity //to push onto the entityList, didn't work either Entity * tempEntity;// Entity entity_list[200]; std::vector < Entity > entity_list;};//only use the single instance entityManager, (makes exporting the class to scripts easy)extern Entity_Factory entityManager;#endif
Any help would be MUCH appreciated I've been stuck on this for a while now :/
[Edited by - BlackShark33 on August 27, 2010 10:26:51 AM]