Hello. I have a need to change the texture of a sprite from one to another. Now that is easy to do with a simple .setTexture(texture). However, it seems that if the textures differ in size, there is a problem.
For example, if I initialize a sprite with a small texture and then change it to a large texture, only a portion of the large texture is assigned to the sprite, a portion exactly the same size as the smaller texture.
Small:
Large:
If I initialize the texture with a large texture and change it to a small texture, the small texture will display with horizonal and vertical lines;
Large:
Small:
Additionally, it seems that the sprite's dimensions can not be changed from what they are initialized to with the first texture. Is there a way to change the textures correctly and be able to force a resize of the sprite to the correct dimensions?
Info: large_texture is a 65 x 65 .jpg, small_texture is a 32 x 32 .jpg
Source code that replicates my problem, using SFML 2.0:
#include <windows.h>
#include <SFML/Graphics.hpp>
using namespace std;
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");
sf::Texture large_texture;
large_texture.loadFromFile("res\\Items\\stone.png");
sf::Texture small_texture;
small_texture.loadFromFile("res\\Items\\stonedust.png");
sf::Sprite sprite1;
sprite1.setTexture(small_texture);//change to either small or large
//for initializing
bool UsingLargeTexture(false);
while (App.isOpen())
{
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
bool decision(false);
if(UsingLargeTexture == true && decision == false)
{
sprite1.setTexture(small_texture);
UsingLargeTexture = false;
decision = true;
}
if(UsingLargeTexture == false && decision == false)
{
sprite1.setTexture(large_texture);
UsingLargeTexture = true;
decision = true;
}
Sleep(500);
}
App.clear();
App.draw(sprite1);
App.display();
}
return EXIT_SUCCESS;
}