1
System / Re: Why console messages slow time "sf::Clock" ?
« on: November 25, 2013, 07:16:43 pm »
Please you can said me if this is good code?
Clock.h
#include "Clock.h"
Clock::Clock(int mls)
{
setTime(mls);
stop = true;
pause = true;
}
void Clock::Update()
{
if (CurrentTime.asMilliseconds() >= Milliseconds)
{
stop = true;
}
else
{
if (pause == false)CurrentTime += Timer.restart();
else Timer.restart();
}
}
void Clock::Play()
{
pause = false;
stop = false;
}
void Clock::Pause()
{
pause = true;
}
void Clock::Stop()
{
stop = true;
CurrentTime = sf::milliseconds(0);
}
void Clock::setTime(int mls)
{
Milliseconds = mls;
}
bool Clock::isFinish()
{
if (CurrentTime.asMilliseconds() >= Milliseconds)return true;
else return false;
}
sf::Time Clock::getTime()
{
return CurrentTime;
}
Clock.h
#ifndef CLOCK_H
#define CLOCK_H
#include <SFML/System.hpp>
class Clock {
public:
Clock(int);//int mls end
void Update();
void Play();
void Pause();
void Stop();
bool isFinish();
void setTime(int);//int mls end
sf::Time getTime();
private:
int Milliseconds;
sf::Clock Timer;
sf::Time CurrentTime;
bool stop;
bool pause;
};
#endif //CLOCK_H
Clock.cpp#define CLOCK_H
#include <SFML/System.hpp>
class Clock {
public:
Clock(int);//int mls end
void Update();
void Play();
void Pause();
void Stop();
bool isFinish();
void setTime(int);//int mls end
sf::Time getTime();
private:
int Milliseconds;
sf::Clock Timer;
sf::Time CurrentTime;
bool stop;
bool pause;
};
#endif //CLOCK_H
#include "Clock.h"
Clock::Clock(int mls)
{
setTime(mls);
stop = true;
pause = true;
}
void Clock::Update()
{
if (CurrentTime.asMilliseconds() >= Milliseconds)
{
stop = true;
}
else
{
if (pause == false)CurrentTime += Timer.restart();
else Timer.restart();
}
}
void Clock::Play()
{
pause = false;
stop = false;
}
void Clock::Pause()
{
pause = true;
}
void Clock::Stop()
{
stop = true;
CurrentTime = sf::milliseconds(0);
}
void Clock::setTime(int mls)
{
Milliseconds = mls;
}
bool Clock::isFinish()
{
if (CurrentTime.asMilliseconds() >= Milliseconds)return true;
else return false;
}
sf::Time Clock::getTime()
{
return CurrentTime;
}