Wednesday, January 7, 2015

Entity (Sprite) Management

This evening, I have started work on the Entity Management system. I call it an entity management system because sprites are traditionally graphical entities and if there were any reason to have a non graphical entity or various types of graphical entities, this would provide a common base. The management system currently uses a std::set in order to keep track of the entities. A pointer to an entity is stored in the set and is used to delete and access the entity. This recommendation from a friend allows the access/deletion of the entities without iterating through the list and reducing performance.

The controlling application must load the texture into the engine before using it in a sprite. Below is an example of a main that would produce a single sprite with a texture. The deletion of the engine will call clear on the texture manager so there is on code visible for that. It will also remove sprites but I provided an example of how to remove just one sprite if needed.




 #include "Engine.hpp"  
 int main(int aargc, const char* argv[])  
 {  
   Engine* engine = new Engine("Game Engine Test", 800, 600);  
   int t0 = engine->addTexture("mario.jpg");  
   Entity* entity = engine->addSprite(t0);  
   engine->run();  
   engine->removeSprite(entity);  
   delete engine;  
   engine = NULL;  
 }  

Below is some scale, rotation and translation of the sprite. This is seamlessly handled by SFML.



No comments:

Post a Comment