Spider& RecyclingSpiderFactory::CreateSpider(const sf::Vector2f SpawnPosition,const float speed,const sf::Vector2i InitialDirection, Mushroomfield& FatherMushroomField){ Spider* spider; //if the recyclebin is empty create a Spider if ( Instance().recycledItems.empty() ) { spider = new Spider(SpawnPosition,speed,InitialDirection, FatherMushroomField); // Tell Teal to let us manually manage the Spider and send to Recycle method spider->SetExternalManagement( RecycleSpider); } else { //sets spider to the top of the recycle stack (grab a previously used spider) spider = Instance().recycledItems.top(); Instance().recycledItems.pop();//remove from stack (since it will be used) // register flea to scene spider->RegisterToCurrentScene(); } //respawn the flea spider->Initialize(SpawnPosition,speed,InitialDirection, FatherMushroomField); return *spider; }
Spider* SpiderFactory::CreateSpider(std::string texture, MushroomField* theField, sf::Vector2f pos, int frameWidth, int frameHeight, int moveDirection) { Spider* e; if ( recycledItems.empty() ) { e = new Spider(texture, theField, frameWidth, frameHeight); e->SetExternalManagement( RecycleSpider ); } else { e = recycledItems.top(); recycledItems.pop(); e->RegisterToCurrentScene(); } e->Initialize(pos, moveDirection); return e; }