Hey,
This is the Screen class I use for rendering Sprites from a Spritesheet (given a source rect and a destination rect)
#include "Screen.hpp"
#include "ResourcePath.hpp"
Screen::Screen(sf::RenderWindow* window) {
_mainWindow = window;
// Load spritesheet
if(!spriteSheet.loadFromFile(resourcePath() + "sprites.png")) {
throw "We failed at loading the sprites.";
}
spriteSheet.setSmooth(true);
sf::ContextSettings settings = _mainWindow->getSettings();
printf("%d", settings.antialiasingLevel);
}
void Screen::render(sf::IntRect sourceRect, sf::IntRect destRect) {
sf::Sprite sprite(spriteSheet);
sprite.scale(1.0 / sourceRect.width * destRect.width, 1.0 / sourceRect.height * destRect.height);
sprite.setTextureRect(sourceRect);
sprite.setPosition(destRect.top, destRect.left);
_mainWindow->draw(sprite);
}
void Screen::render(sf::IntRect sourceRect, sf::IntRect destRect, bool centered) {
sf::Sprite sprite(spriteSheet);
sprite.scale(1.0 / sourceRect.width * destRect.width, 1.0 / sourceRect.height * destRect.height);
sprite.setTextureRect(sourceRect);
if(centered)
sprite.setOrigin(destRect.width / 2.0, destRect.height / 2.0);
sprite.setPosition(destRect.left, destRect.top);
_mainWindow->draw(sprite);
}
void Screen::clear() {
_mainWindow->clear(sf::Color(13, 15, 30));
}
This works pretty fine when the source rect size equals the dest rect size or if the dest rect size is higher than the source rect size. But when I scale stuff down (e.g. sourceRect = 0,0,256,256 destRect = 0,0,50,50) it looks very pixelated (see Attachment).
I already tried setting sf::ContextSettings:antialiasingLevel for my renderWindow, that didn't change anything.
Is there a way to properly scale images down or is my approach of rendering sprites from a spritesheet / texture totally wrong?
[attachment deleted by admin]