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

Author Topic: deleting texture  (Read 3169 times)

0 Members and 1 Guest are viewing this topic.

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
deleting texture
« 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?


shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: deleting texture
« Reply #1 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.

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: deleting texture
« Reply #2 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?
« Last Edit: May 13, 2015, 07:52:30 pm by lorence30 »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: deleting texture
« Reply #3 on: May 13, 2015, 07:51:01 pm »
Copy your alien (sprite) and just remove the dead copies.

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: deleting texture
« Reply #4 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]);
  }
}

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: deleting texture
« Reply #5 on: May 13, 2015, 07:54:36 pm »
@shadowmouse
@Jesper Juhl

okay thanks guys. i get all the idea :)

thank you.