Hi, I'm trying to position a sprite relative to another. I have 2 sprites, one for the character and one for the head. The view is top down, when he is standing the head and character are aligned but when I do a slide the head remains in the center, I need to position the head in the correct place applying and offset form the center. How can I achieve this? I leave a beautiful image discribing the problem
I have this code but the translation isn't working, I can't see the head (it might be outside the screen)
void FieldPlayer::draw()
{
m_sprite.setPosition(Game::SCALE * m_body->GetPosition().x, Game::SCALE * m_body->GetPosition().y);
m_sprite.setRotation(Game::RadiansToDegrees(m_body->GetAngle()));
Game::GetWindow()->draw(m_sprite);
head_sprite.setPosition(Game::SCALE * m_body->GetPosition().x, Game::SCALE * m_body->GetPosition().y);
head_sprite.setRotation(Game::RadiansToDegrees(m_body->GetAngle()));
// move the head back if sliding
if (PlayerState.sliding) {
sf::Transform t = head_sprite.getTransform();
t.translate(-52.f, -10.f); ???
Game::GetWindow()->draw(head_sprite, t);
}
else {
Game::GetWindow()->draw(head_sprite);
}
}
Note: I need the code to consider rotations also