Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: image to multipart texture  (Read 2247 times)

0 Members and 2 Guests are viewing this topic.

sadebegam

  • Newbie
  • *
  • Posts: 3
    • View Profile
image to multipart texture
« 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!
« Last Edit: January 12, 2016, 10:26:43 pm by sadebegam »

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: image to multipart texture
« Reply #1 on: January 12, 2016, 10:37:16 pm »
load test.jpg into an sf::Image and then use loadFromImage().

sadebegam

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: image to multipart texture
« Reply #2 on: January 12, 2016, 10:42:21 pm »
 reading from ram is so faster
thank You!

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: image to multipart texture
« Reply #3 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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

sadebegam

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: image to multipart texture
« Reply #4 on: January 12, 2016, 10:57:28 pm »
thank You too!
I try your way soon!