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

Author Topic: Unsetting a Sprite's Image  (Read 3595 times)

0 Members and 1 Guest are viewing this topic.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Unsetting a Sprite's Image
« on: June 09, 2009, 03:10:08 am »
to avoid the "SetSubRect" of sprites, I oftenly do a

Code: [Select]
spr.SetImage(Image());
spr.SetImage(theNewImage);


And it works correctly.



But if I don't set a real image afterwards, the behaviour differs from a "fresh sprite": It draws a white rectangle instead of "nothing"



Code: [Select]
App.Draw(spr);                  //nothing
spr.SetImage(someLoadedImage);
App.Draw(spr);                  //an image
spr.SetImage(Image());
App.Draw(spr);                  //a white rect


I have a HUD display with prerendered numbers. 6 sprites, one for each number.
So setting the number is basically dividing by 10 a bunch of times and getting the modulo 10, and for each digit I have an image.

I wanted to reset the sprite to do "spaces", instead of showing zeros to the left. And assigning an alpha=0 image is to much of a hack.


Is there another poper whay I should know?
Thanks
-Martín

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Unsetting a Sprite's Image
« Reply #1 on: June 09, 2009, 06:43:47 am »
Well, you could always just not draw the sprite...

Or perhaps you just don't even have sprites you don't need. You could use a linked list or vector to store only as many sprites as you actually have digits, while adding/removing as needed.

Sorry, since that doesn't address your question of unsettling images at all. :)

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Unsetting a Sprite's Image
« Reply #2 on: June 09, 2009, 07:25:48 am »
No problem :)

I know it can be worked around with a bunch of bools.

But the behaviour should be consistent between a new sprite and the one being reset, I think.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unsetting a Sprite's Image
« Reply #3 on: June 09, 2009, 07:57:24 am »
The new sprite is white as well, it's just that its size is null. If you also reset the subrect you will get the same result.

BTW, why don't you use a sf::String to draw your digits?
Laurent Gomila - SFML developer

dunce

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Unsetting a Sprite's Image
« Reply #4 on: June 09, 2009, 01:28:18 pm »
I used sprites for digits and other symbols too. It made it possible to use visual effects like sequential appearance of symbols with scaling, rotation etc.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Unsetting a Sprite's Image
« Reply #5 on: June 10, 2009, 05:41:35 pm »
Quote from: "dunce"
I used sprites for digits and other symbols too. It made it possible to use visual effects like sequential appearance of symbols with scaling, rotation etc.


That's my reason. But for much less: The numbers are pre-textured with some effects, and the font's license does not allow to ship the font file with anything.

Quote from: "Laurent"
The new sprite is white as well, it's just that its size is null. If you also reset the subrect you will get the same result.

I'll try that!
But, can I reset the sub rect if the image is NULL?

I remember I posted about incongruent behaviour for SetSubRect if the internal image was or wasn't NULL... have you changed this?

I could set the sub rect before and then SetImage(Image())... but again, the order shouldn't matter.
I'll never be confortable with the SetImage function
 :lol:

-Martín