#include "xSpriteGroup.h" /** clean SDL objects */ xSpriteGroup::~xSpriteGroup(){ _mutex.lock(); _sprites.clear(); _mutex.unlock(); } /** default constructor */ xSpriteGroup::xSpriteGroup(){ } /** adds a sprite to the group */ void xSpriteGroup::add(xSprite* sprite){ _mutex.lock(); _sprites.insert(sprite); _mutex.unlock(); } /** removes a sprite from the group */ void xSpriteGroup::remove(xSprite* sprite){ _mutex.lock(); _sprites.erase(sprite); _mutex.unlock(); } /** set absolute move for each sprite */ void xSpriteGroup::moveTo(int x, int y){ _mutex.lock(); _move.x = x; _move.y = y; _mutex.unlock(); } /** draws to renderer */ void xSpriteGroup::draw(SDL_Renderer* renderer){ _mutex.lock(); set::iterator it; for( it = _sprites.begin() ; it != _sprites.end() ; it++ ){ (*it)->draw(renderer); } _mutex.unlock(); } /** animation process */ void xSpriteGroup::tick(const uint32_t ticks){ _mutex.lock(); uint32_t time_index = ticks / _animation_interval; _active_sprite = time_index % _sprites.size(); _mutex.unlock(); } /** orchestrate the animation */ void xSpriteGroup::animate(uint32_t interval){ _animation_interval = interval; xApplication::get()->addOrchestrable(this); } /** stops orchestrating the animation */ void xSpriteGroup::freeze(){ xApplication::get()->removeOrchestrable(this); }