/** * \brief Sets the animation set id to use for the sword sprite. * \param sprite_id The sword sprite animation set id. * An empty string means no sword sprite. */ void HeroSprites::set_sword_sprite_id(const std::string& sprite_id) { if (sprite_id == this->sword_sprite_id) { return; } this->sword_sprite_id = sprite_id; std::string animation; int direction = -1; if (sword_sprite != nullptr) { // Delete the previous sprite, but save its animation and direction. if (sword_sprite->is_animation_started()) { animation = sword_sprite->get_current_animation(); direction = sword_sprite->get_current_direction(); } hero.remove_sprite(*sword_sprite); sword_sprite = nullptr; } if (!sprite_id.empty()) { // There is a sword sprite specified. sword_sprite = hero.create_sprite(sprite_id, "sword"); sword_sprite->enable_pixel_collisions(); sword_sprite->set_synchronized_to(tunic_sprite); if (animation.empty()) { sword_sprite->stop_animation(); } else { sword_sprite->set_current_animation(animation); sword_sprite->set_current_direction(direction); } } has_default_sword_sprite = (sprite_id == get_default_sword_sprite_id()); reorder_sprites(); recompute_sprites_bounding_box(); }
/** * \brief Sets the animation set id to use for the tunic sprite. * \param sprite_id The tunic sprite animation set id. */ void HeroSprites::set_tunic_sprite_id(const std::string& sprite_id) { if (sprite_id == this->tunic_sprite_id) { return; } this->tunic_sprite_id = sprite_id; std::string animation; int direction = -1; if (tunic_sprite != nullptr) { // Delete the previous sprite, but save its animation and direction. animation = tunic_sprite->get_current_animation(); direction = tunic_sprite->get_current_direction(); hero.remove_sprite(*tunic_sprite); tunic_sprite = nullptr; } tunic_sprite = hero.create_sprite(sprite_id, "tunic"); tunic_sprite->enable_pixel_collisions(); if (!animation.empty()) { set_tunic_animation(animation); tunic_sprite->set_current_direction(direction); } has_default_tunic_sprite = (sprite_id == get_default_tunic_sprite_id()); // Synchronize other sprites to the new tunic sprite. if (sword_sprite != nullptr) { sword_sprite->set_synchronized_to(tunic_sprite); } if (shield_sprite != nullptr) { shield_sprite->set_synchronized_to(tunic_sprite); } reorder_sprites(); recompute_sprites_bounding_box(); }
/** * \brief Sets the animation set id to use for the shield sprite. * \param sprite_id The shield sprite animation set id. * An empty string means no sword sprite. */ void HeroSprites::set_shield_sprite_id(const std::string& sprite_id) { if (sprite_id == this->shield_sprite_id) { return; } this->shield_sprite_id = sprite_id; std::string animation; int direction = -1; if (shield_sprite != nullptr) { // Delete the previous sprite, but save its animation and direction. if (shield_sprite->is_animation_started()) { animation = shield_sprite->get_current_animation(); direction = shield_sprite->get_current_direction(); } shield_sprite = nullptr; } if (!sprite_id.empty()) { // There is a shield sprite specified. shield_sprite = std::make_shared<Sprite>(sprite_id); shield_sprite->set_synchronized_to(tunic_sprite); if (animation.empty()) { shield_sprite->stop_animation(); } else { shield_sprite->set_current_animation(animation); shield_sprite->set_current_direction(direction); } } has_default_shield_sprite = (sprite_id == get_default_shield_sprite_id()); recompute_sprites_bounding_box(); }