SFML community forums

Help => Graphics => Topic started by: sadebegam on January 12, 2016, 10:20:28 pm

Title: image to multipart texture
Post by: sadebegam on January 12, 2016, 10:20:28 pm
Hello my friends.

I am new to SFML.
Is there faster way to load one image to 16 part than this:

for(int i=0;i<4;i++)
                for(int j=0;j<4;j++)
        {
        Texture1[i][j].loadFromFile("test.jpg",sf::IntRect(i*60,j*60,60,60));
        Sprite1[i][j].setTexture(Texture1[i][j]);
        Sprite1[i][j].setPosition(i*60,j*60);
                }
 

my way is so slow!
Title: Re: image to multipart texture
Post by: shadowmouse on January 12, 2016, 10:37:16 pm
load test.jpg into an sf::Image and then use loadFromImage().
Title: Re: image to multipart texture
Post by: sadebegam on January 12, 2016, 10:42:21 pm
 reading from ram is so faster
thank You!
Title: Re: image to multipart texture
Post by: zsbzsb on January 12, 2016, 10:42:41 pm
Load you image into 1 texture and use sf::Sprite::setTextureRect(...). There is no need for you to split your image into 16 textures.
Title: Re: image to multipart texture
Post by: sadebegam on January 12, 2016, 10:57:28 pm
thank You too!
I try your way soon!