SFML community forums
Help => Graphics => Topic started 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?
-
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.
-
what a fast reply.
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:
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?
-
Copy your alien (sprite) and just remove the dead copies.
-
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:
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]);
}
}
-
@shadowmouse
@Jesper Juhl
okay thanks guys. i get all the idea :)
thank you.