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

Author Topic: Sprite.SetImage memory trouble  (Read 5101 times)

0 Members and 1 Guest are viewing this topic.

Saile

  • Newbie
  • *
  • Posts: 3
    • View Profile
Sprite.SetImage memory trouble
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sprite.SetImage memory trouble
« Reply #1 on: October 29, 2007, 02:39:06 am »
It is actually a pointer. Sprites don't duplicate their image, that would be stupid.
Laurent Gomila - SFML developer

Saile

  • Newbie
  • *
  • Posts: 3
    • View Profile
Sprite.SetImage memory trouble
« Reply #2 on: October 29, 2007, 04:12:53 pm »
Sorry if I said something wrong, but I don't know how to solve my problem :(

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sprite.SetImage memory trouble
« Reply #3 on: October 29, 2007, 04:52:51 pm »
Which problem ?
Laurent Gomila - SFML developer

Saile

  • Newbie
  • *
  • Posts: 3
    • View Profile
Sprite.SetImage memory trouble
« Reply #4 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sprite.SetImage memory trouble
« Reply #5 on: October 30, 2007, 02:09:08 am »
Can you show us some code ?
Laurent Gomila - SFML developer

Henrik.Flink

  • Newbie
  • *
  • Posts: 21
    • View Profile
Sprite.SetImage memory trouble
« Reply #6 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
  • [y].Create(&tileImage);


Hope it helped...

 

anything