SFML community forums

Help => Graphics => Topic started by: lorence30 on May 13, 2015, 07:46:04 pm

Title: deleting texture
Post by: lorence30 on May 13, 2015, 07:46:04 pm
sprite.setTextureRect(sf::IntRect(0,0,32*6,32*6));
i created multiple aliens from 1 alien,
is it possible to delete the selected alien from the window?

Title: Re: deleting texture
Post by: shadowmouse on May 13, 2015, 07:47:17 pm
Use a bool variable/array of bools to determine which aliens should be drawn and then just don't draw the alien that you want to remove from the screen.
EDIT: If you are using a single sprite for all the aliens, then that is basically pointless as it is easy enough to move them all simultaneously and sprites are lightweight.
Title: Re: deleting texture
Post by: lorence30 on May 13, 2015, 07:48:48 pm
what a fast reply.

Quote
Use a bool variable/array of bools to determine which aliens should be drawn and then just don't draw the alien that you want to remove from the screen.
I get your whole point, only the true ones will be drawn.

but how do i do that if all aliens are only a duplicate from 1 alien

EDIT:
Quote
EDIT: If you are using a single sprite for all the aliens, then that is basically pointless as it is easy enough to move them all simultaneously and sprites are lightweight.
do you mean more sprite for 1 texture?
Title: Re: deleting texture
Post by: Jesper Juhl on May 13, 2015, 07:51:01 pm
Copy your alien (sprite) and just remove the dead copies.
Title: Re: deleting texture
Post by: shadowmouse on May 13, 2015, 07:52:11 pm
I would set that up by making an array of sprites which all reference the same texture (a single alien) and then an equivalent array of bools.Something like this:
Code: [Select]
sf::Texture alienTexture;
sf::Sprite aliens[10];
bool visible[10];

alienTexture.loadFromFile("image.png");
for(int i (0); i < 10; i = i + 1)
{
  aliens[i].setTexture(alienTexture);
}
...
for(int i (0); i < 10; i = i + 1)
{
  if(visible[i])
  {
    window.draw(aliens[i]);
  }
}
Title: Re: deleting texture
Post by: lorence30 on May 13, 2015, 07:54:36 pm
@shadowmouse
@Jesper Juhl

okay thanks guys. i get all the idea :)

thank you.