SFML community forums

Help => Graphics => Topic started by: Saile on October 28, 2007, 02:23:45 pm

Title: Sprite.SetImage memory trouble
Post by: Saile on October 28, 2007, 02:23:45 pm
Im working with tiles and have a big image with many pictures, I use the sprite.SetImage & sprite.SetSubRect to my class. That makes all instances I create have that big image stored for them selves which increases the memory radical. Would it be better if the Image worked as a pointer, if it isn't?
Title: Sprite.SetImage memory trouble
Post by: Laurent on October 29, 2007, 02:39:06 am
It is actually a pointer. Sprites don't duplicate their image, that would be stupid.
Title: Sprite.SetImage memory trouble
Post by: Saile on October 29, 2007, 04:12:53 pm
Sorry if I said something wrong, but I don't know how to solve my problem :(
Title: Sprite.SetImage memory trouble
Post by: Laurent on October 29, 2007, 04:52:51 pm
Which problem ?
Title: Sprite.SetImage memory trouble
Post by: Saile on October 29, 2007, 05:56:22 pm
About that all new instances i create of a sertain class has a sprite with the SetSubRect of the huge tile image. I just need that SubRect image for that instance, not the whole image. Because when I do so the memory increases as much as the images size for all instances.
Title: Sprite.SetImage memory trouble
Post by: Laurent on October 30, 2007, 02:09:08 am
Can you show us some code ?
Title: Sprite.SetImage memory trouble
Post by: Henrik.Flink on October 30, 2007, 02:15:29 pm
Hmm i maybe get what your problem is and my suggestion is to do:

you can have a class named TileMap for example with a sfImage tileImage.

then you have a class for each tile which have a sfSprite and a create function with a sfImage pointer: Create(sfImage* tileImage);
So you can set the sprite to the image pointer like this:
tileSpriteName.SetImage(*tileImage) in the Create function. Then you can set the sub rect in each tile using the same image.

Also in the tileMap class when you call the Create function it should(could) look like this: tile

Hope it helped...