So I made this program and I totally was able to grab sprites until I added code for animation. All of the sudden when I run it, it's not showing anything. Here is the code. Why doesn't it work?
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
//#include "Chardicks.h"
//#include "Keystrokes.h"
using namespace sf;
using namespace std;
Texture texture;
Sprite Charmander;
int main()
{
RenderWindow window(VideoMode(640, 480), "FUCKING CHARMANDER!");
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
}
Clock TIMER;
TIMER.restart();
Time t2 = milliseconds(333);
Time t1 = TIMER.getElapsedTime();
int step = 0;
TIMER.restart();
if (t1 >= milliseconds(333))
{
window.clear();
texture.loadFromFile("PokeSprites.png", IntRect(1,1,32,32));
Charmander.setTexture(texture);
step = 1;
TIMER.restart();
window.draw(Charmander);
window.display();
}
if (t1 >= t2)
{
window.clear();
texture.loadFromFile("PokeSprites.png", IntRect(0,32,32,32));
Charmander.setTexture(texture);
step = 0;
TIMER.restart();
window.draw(Charmander);
window.display();
}
}
return 0;
}
TIMER.restart();
Time t1 = TIMER.getElapsedTime();
t1 is probably 0ms or close to 0ms.
So it is never >= milliseconds(333) or >= t2 (which is also milliseconds(333) lol.).
When posting pieces of code (especially long ones) in the forum, you have to surround it with code tags. It greatly improves readability and you'll be more likely to get answers.
(http://i.imgur.com/XoEkbUI.png)
TIMER.restart();
Time t1 = TIMER.getElapsedTime();
t1 is probably 0ms or close to 0ms.
So it is never >= milliseconds(333) or >= t2 (which is also milliseconds(333) lol.).
When posting pieces of code (especially long ones) in the forum, you have to surround it with code tags. It greatly improves readability and you'll be more likely to get answers.
(http://i.imgur.com/XoEkbUI.png)
Thanks, I changed it.
Doesn't getElapsedTime get the time of how long the program has been running so far? So wouldn't it never be 0ms?