-
Hello all,
i read in the post from Laurent (http://en.sfml-dev.org/forums/index.php?topic=7572.0) that its possible to flip a sprite using textureRec with negative values.
with this my sprite is showing:
pSprite.setTextureRect(sf::IntRect(9,7,21,38));
after Laurents post i think i can use
pSprite.setTextureRect(sf::IntRect(9,7,-21,-38));
for flipping my sprite, but my sprite is disappear and not flipped.
Did i understand sth. wrong?
best regards
-
You mustn't blindly apply the negative width/height, you have to think about what result you get. If left = 9 and width = -21, what's the right coordinate? It's 9 - 21 = -12. So to keep the same rectangle, you must set the left coordinate to be the right. In this case, "left" should be 30 so that the other coordinate (the actual left) is still 9 when you add the width (-21).
In other words, when you invert width and height you must consider that the members "left" and "top" of the rectangle are actually the right and the bottom.
-
Well you missed his point entirely. ;)
// flip X
sprite.setTextureRect(sf::IntRect(width, 0, -width, height));
So your code should be:
Flipped along the x axis:
pSprite.setTextureRect(sf::IntRect(21+9,7,-21,38));
Flipped along the y axis:
pSprite.setTextureRect(sf::IntRect(9,38+7,21,-38));
Both:
pSprite.setTextureRect(sf::IntRect(21+9,38+7,-21,-38));
-
Hello Laurent and eXpl0it3r,
first, thanks for your help.
i trying to understand. If i flipp my Sprite, i must use the x/y coord. from the "opposite" site and then negative values for hight and width.So the x/y coord. is 30/45, i have check this out by a graphic tool. If using now
pSprite.setTextureRect(sf::IntRect(30,45,-21,-38));
my sprite is still disappear as before.
Did i still understand sth. wrong? - sorry my english is not the best :D . . .
-
Seems to be working smoothly here. ;)
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
sf::Texture tex1;
tex1.loadFromFile("test.png");
sf::Sprite spr;
spr.setTexture(tex1);
spr.setTextureRect(sf::IntRect(9,7,21,38));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
spr.setTextureRect(sf::IntRect(9,7,21,38));
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Return))
spr.setTextureRect(sf::IntRect(21+9,38+7,-21,-38));
window.clear(sf::Color::Blue);
window.draw(spr);
window.display();
}
}
[attachment deleted by admin]
-
Hello eXpl0it3r,
iam using your code and your test.png. I get exactly the same problem here as in my code and my png ... the sprite disappears. What the hell :( . . .
iam stumped.
-
Which revision of SFML 2 are you using?
-
Hey Laurent,
i download the lib from the main site:
C++ | version 2.0 RC -> Windows 32 bits - Visual C++ 2010 (11.4 MB)
-
Hey Laurent,
its me again. Ive download now the nightly build (latest 2013-02-19 SFML 2.0) from eXpl0it3r's Signature, and with this everything works fine.
i hope this help you (?) - and thanks all for the help.
best regards
Chi
-
and with this everything works fine.
I'm glad it works again!
i hope this help you (?) - and thanks all for the help.
Since my Nightly Builds are newer than the RC release, it was a problem that seems to have been already fixed. ;)