Bonjour, j'ai un problème avec restart() qui ne fonctionne pas dans ce code et je ne comprends pas pourquoi, je cherche depuis un petit moment maintenant..
main.cpp:
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include "animation.h"
#include "Lamp.h"
#include <iostream>
std::vector <Lamp*> Lamp::LampList;
int main(){
Lamp *nouvelleLamp=new Lamp();
while (true)
{
nouvelleLamp->getAnimation(0).play();
}
system("pause");
return 0;
}
animation.h:
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#ifndef DEF_ANIMATION
#define DEF_ANIMATION
class Animation
{
private:
sf::Clock m_timer;
sf::Time m_tAnim;
public:
Animation (sf::Time time);
void play();
};
#endif
Lamp.h:
#ifndef LAMP_H
#define LAMP_H
#include "animation.h"
using namespace std;
class Lamp
{
public:
Lamp();
static std::vector <Lamp*> LampList;
Animation getAnimation(int i) { return m_animationList[i]; }
void addAnimation (Animation &newAnimation) { m_animationList.push_back(newAnimation);}
std::vector <Animation> m_animationList;
};
#endif // LAMP_H
Lamp.cpp:
#include "Lamp.h"
Lamp::Lamp()
{
Animation*animTemp=new Animation(sf::milliseconds(600));
this->addAnimation(*animTemp);
Lamp::LampList.push_back(this);
}
animation.cpp:
#include "animation.h"
#include <iostream>
Animation::Animation(sf::Time tAnim)
{
m_tAnim=tAnim;
}
void Animation::play()
{
if (m_timer.getElapsedTime()>=m_tAnim)
{
std::cout << m_timer.getElapsedTime().asMilliseconds() << " ";
m_timer.restart();
}
}