I searched in the forums and found someone with a similar problem, but I'd like to know the details. Everything is drawn properly and it even moves according to the semi-circle function I am using, but when I set origin to (400, 300) and run it, the sprite disappears, as if it had not even been drawn or displayed in the first place.
I've checked my code over and over, but found nothing wrong in it, it just goes mad when I set the origin, I'll post it just in case, but I doubt it's that.
int main()
{ ///Test to learn how to draw individual bullets
sf::RenderWindow window(sf::VideoMode(800, 600), "Bullet Testing");
sf::Event event;
sf::IntRect d;
sf::Image img; img.loadFromFile("Images\\Bullets\\HQtest.jpg");
img.createMaskFromColor(sf::Color::Black, 0);
sf::Texture Img;
Img.loadFromImage(img, d);
Img.setSmooth(true);
sf::Sprite Sprite;
sf::Sprite Sprite2;
sf::Sprite Sprite3;
Sprite.setTexture(Img, true); Sprite2.setTexture(Img, true); Sprite3.setTexture(Img, true);
Sprite.setColor(sf::Color(255, 255, 0, 200));
Sprite2.setColor(sf::Color(255, 0, 255, 200));
Sprite3.setColor(sf::Color(0, 255, 255, 200));
Sprite.setPosition(400, 300);
Sprite2.setPosition(110, 0);
Sprite3.setPosition(120, 0);
window.setFramerateLimit(60);
///For the circle function.
index x = -25; const short int r = 25;
///Game loop.
while (window.isOpen())
{ // check all the window's events that were triggered since the last iteration of the loop
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(Sprite); window.draw(Sprite2); window.draw(Sprite3);
Sprite.setOrigin(400, 300);
if (x <= r )
{ Sprite.setPosition(x, sqrt((r * r) - (x * x))); ++x; }
window.display();
}
}
return 0;
}
Edit: Just made some tests only to find myself even more baffled than before, if I remove the if that handles the sprite's movement it actually appears, but at position (0, 0), if I remove the setOrigin function it properly appears at the center of the renderwindow. Is this all due to my graphics card or is there actually something wrong with the code?
So what I would need to do before setting it's position is to set the origin of the given sprite in the point I want it to be displayed, then do something like this:
Sprite.setOrigin(400, 300);
Sprite.setPosition(Sprite.getOrigin());
Which I already did, to get nothing. The sprite doesn't even appear if I do this. Everytime I set the origin to something the sprite doesn't appear, whether I move it afterwards or not.
I know what the origin is and that it's used to affect transformations done after being told that it had a new origin and I intend to do that, so that it moves my sprite in a circular fashion around the given origin. That is my intention. I know that it will not mantain it's position, so my problem is not that, but rather it is that it doesn't move according to the origin set. in fact it doesn't even appear at all if I use the setOrigin function.
I didn't quite get your post so I did what I thought you told me to and tried to re-explain.
And the reason I am also blaming my graphics card is because of this:
http://en.sfml-dev.org/forums/index.php?topic=6696.msg44048 (http://en.sfml-dev.org/forums/index.php?topic=6696.msg44048)
Sprite.setOrigin(400, 300);
Sprite.setPosition(Sprite.getOrigin());
This should make the sprite appear in same spot as if you didn't move it at all. Does it appear then?
Do other sprites appear?
Also, what class/type is that:
index x = -25
I forgot to add that, it's just a typedef for short int, I use it for any number I may use as an index of some sort.
And other sprites do appear, the one that isn't shown is the one whose origin is set.
I'll attach the image and other than the image and the index variable there is nothing left out that you may need to run it.
I just noticed but I should have used:
index x = -r
instead of:
index x = -25
Since in order to make it a semi-circular function it has to have a domain from -r to r, where r is the radious. Just as a small side-note in case it is needed.
Edit: Here's the code:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(400, 400), "SFML works!");
sf::CircleShape shape(10.f);
shape.setOrigin(100 , 100);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
What happens is that with just using the function setOrigin (this time in a Circle Shape) the image is not shown, if I remove the line it is properly shown, else it's just a black screen. The same happens when I use an image, I may have made the explanation at first complicated, but that's the summary of what's happening.
[attachment deleted by admin]