Hi, SFML community, I'm having issues trying to get a sprite to be fixed to a certain screen position even when the camera is moving, pretty much what I need is having a sprite with a fixed position on the screen or rather a fixed position of the camera and make it remain in there even when the view is moving around. but I want to achieve this, without using another view. I know it would be better to have a view for the HUID but, its just one sprite in this case.
I attach a gif to the problem in question.
Here is my code without my tries, as you can see I have a bool in case a sprite is fixed.
void RenderSystem::update(std::shared_ptr<sf::RenderWindow> renderer, std::unique_ptr<Bread::AssetManager>& assetManager, sf::View & camera)
{
for (size_t i(0);i<layers.size();i++)
{
for(auto &it: *(*layers[i].getEntities()).getEntities())
{
auto& transform(it.getComponent<TransformComponent>());
auto& sprite(it.getComponent<SpriteComponent>());
auto& cameraPos(camera.getCenter());
auto& cameraSize(camera.getSize());
sf::Vector2f cameraCorner(cameraPos.x - (cameraSize.x / 2), cameraPos.y - (cameraSize.y / 2));
sf::FloatRect entityRect(transform.position.x, transform.position.y, transform.scale.x * sprite.width, transform.scale.y * sprite.height);
if(!isInsideOfCamera(entityRect,camera) and !sprite.isFixed)
{
continue;
}
sf::IntRect srcRect = sprite.srcRect;
sf::Vector2f destRect =
{
(transform.position.x),
(transform.position.y)
};
sf::Sprite sprite2(*assetManager->getTexture(sprite.assetId),srcRect);
sprite2.setPosition(destRect);
sprite2.setScale(transform.scale.x,transform.scale.y);
renderer->draw(sprite2);
}
}
}
Thanks in advance. Have a good day
/