After many battles with IntRect i successfully initialized it like this:
player.cpp
Player::Player(VideoMode VMo){
playerRectSourceSprite.left = 0;
playerRectSourceSprite.top = 0;
playerRectSourceSprite.width = 60;
playerRectSourceSprite.height = 60;
}
Why i couldn't do this like this:
playerRectSourceSprite(0, 0, 60, 60);
or like this
IntRect playerRectSourceSprite(0, 0, 60, 60); // I know this one is definitely wrong but i tried this as well
Of course i could initialize it this way:
playerRectSourceSprite = {0, 0, 60, 60}; // but then i receive warnings and i read this isn't best way of initializing
but in the same moment i can initialize Sprite position in the same constructor in a way i can't IntRect:
playerS.setPosition(50, 450);
Is there any reason behind it, or maybe there is different way to initialize IntRect collectively? Or, maybe, i am doing something incorrectly?
This is not a SFML problem, and it has nothing to do with the constructors of SFML classes. You just lack some basic understanding of C++ itself.
Either you use the initialization list of the constructor to construct your rectangle with arguments directly:
Player::Player(VideoMode VMo) :
playerRectSourceSprite(0, 0, 60, 60)
{
}
... or you assign a new IntRect after its construction:
Player::Player(VideoMode VMo)
{
playerRectSourceSprite = sf::IntRect(0, 0, 60, 60); // or using C++11 uniform brace initialization
}
but then i receive warnings
Which ones?