Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Aklus

Pages: [1]
1
System / Re: Time and clock
« on: January 16, 2015, 11:46:44 pm »
I'm actually reading a c++ book, I just want to remember everything by programming very simple game. :)

I just forgot about changing "." to "->" in "clock.getElapsedTime". That was a thing which was I doing wrong before.

 Thanks for the reply.

2
System / Re: Time and clock
« on: January 16, 2015, 11:03:28 pm »
I tried it before, but it didn't work properly for me as well.

logic scope;
sf::Clock clock;
while(window.isOpen())
{
scope.fire(&clock);
}
 

void logic::fire(sf::Clock *clock)
{
    sf::Time shot;
    shot -> clock.getElapsedTime();                   //Here is an error "base operand -> has non-pointer type sf::Time"
    sf::Time reload = sf::milliseconds(1500);
    std::cout << shot.asMilliseconds();
    if(sf::Mouse::isButtonPressed(sf::Mouse::Left) and shot >= reload )
    {
        std::cout << "Sup m8" <<std::endl;
        clock -> restart();
    }
}
 

What am i doing wrong now?

3
System / Time and clock
« on: January 16, 2015, 10:47:47 pm »
Hi, i am trying to create my first game in SFML but im having problems with Time and clocks.
Main function looks like this:
logic scope;
while(window.isOpen())
{
scope.fire();
}
 

"fire" looks like this:

void logic::fire()
{
    sf::Clock clock;
    sf::Time shot;
    shot = clock.getElapsedTime();
    sf::Time reload = sf::milliseconds(1500);
    std::cout << shot.asMilliseconds();
    if(sf::Mouse::isButtonPressed(sf::Mouse::Left) and shot >= reload )
    {
        std::cout << "Sup m8" <<std::endl;
        clock.restart();
    }
}
 

As you can see i want to allow my player to shoot but only after 1.5 seconds from last shot. The problem is that "shot.asMilliseconds()" is always showing me that his time is 0. Anyone have any idea what am I doing wrong?

Pages: [1]
anything