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?