SFML community forums

Help => Graphics => Topic started by: stevend on August 11, 2009, 07:44:21 am

Title: problem with SetSubRect
Post by: stevend on August 11, 2009, 07:44:21 am
ok so here is my code:

(i am using the resource manager to manage images found in the wiki)

Code: [Select]

sf::Image* image = gImageManager.getResource( tilesetfilelocation );
if( image != NULL )
{
sf::Sprite sprite;
sprite.SetImage( *image );

sprite.SetSubRect(sf::IntRect(32, 32, 32, 32));
sprite.SetCenter(0,0);

sprite.SetPosition((float)32,(float)32);
map.push_back(sprite);
}
else
cout << "File not found! " << tilesetfilelocation << endl;


my problem is that when is when i comment out this, and draw all the sprites (map is a vector array of sprites)

Code: [Select]

sprite.SetSubRect(sf::IntRect(32, 32, 32, 32));


it draws the entire image fine. but when i attempt to draw one tile from this by leaving the above line UNcommented i get nothing.

i cant get SetSubRect to work for the life of me.

the image i am using is a tile set with 32x32 tiles in jpg format, one used by rpgmaker.

any ideas?
Title: problem with SetSubRect
Post by: Laurent on August 11, 2009, 07:55:34 am
Just read the documentation of sf::IntRect please ;)
Title: problem with SetSubRect
Post by: stevend on August 11, 2009, 08:03:03 am
could you possibly provide a link? and a little help?

ive searched through the doxygen and all i could find was a page on sf::Rect and it didnt reeally help me what so ever.

thanks, any help is appreciated.
Title: problem with SetSubRect
Post by: Laurent on August 11, 2009, 08:06:38 am
Sure :)
http://www.sfml-dev.org/documentation/1.5/classsf_1_1Rect.htm#0f19f5cf78eb52f122b904fb258acfce

As you can see it's not (x, y, width, height) but (left, top, right, bottom).
Title: problem with SetSubRect
Post by: stevend on August 11, 2009, 04:58:34 pm
wow now i feel like a dumbass  :roll:  thanks for the help