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

Author Topic: asSeconds(),asMicroseconds() and asMilliseconds() functions not being recognized  (Read 1558 times)

0 Members and 1 Guest are viewing this topic.

Programmy

  • Newbie
  • *
  • Posts: 19
    • View Profile
hello, Im having trouble implementing asSeconds(), asMicroseconds() and asMilliseconds()
Im tinkering with a particular code in the book SFML Game development with examples
but my compiler doesn't recognize the three functions, ive tried changing the preprocessors
to <SFML/System.hpp> then tried <SFML/System/Time.hpp> no luck,
i'm getting the error sf::RenderWindow has no member asSeconds
#include <SFML/Graphics.hpp>
#include <SFML/System/Time.hpp>
#include <iostream>

void main(int argc, char** argv[]) {

        sf::RenderWindow window(sf::VideoMode(640, 480),"Bouncing mushroom.");
        sf::Texture texture;
        sf::RenderWindow time;
        sf::Clock clock;


        sf::Time time = clock.getElapsedTime();
        float seconds = time.asSeconds();
        sf::Int32 milliseconds = time.asMilliseconds();
        sf::Int64 microseconds = time.asMicroseconds();

       

        time = clock.restart();
       
        texture.loadFromFile("c:/Users/jason/source/repos/SFML2/Eagle.png");
       
        sf::Sprite mushroom(texture);
        sf::Vector2u size = texture.getSize();
         
       

        mushroom.setOrigin(size.x / 2, size.y / 2);
        sf::Vector2f increment(0.4f, 0.4f);
       
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                       
                        if (event.type == sf::Event::Closed)
                        {
                                window.close();

                        }
                }
                if ((mushroom.getPosition().x + (size.x / 2) >
                        window.getSize().x && increment.x > 0) ||
                        (mushroom.getPosition().x - (size.x / 2) < 0 &&
                                increment.x < 0))
                {
                        // Reverse the direction on X axis.
                        increment.x = -increment.x;
                }
                if ((mushroom.getPosition().y + (size.y / 2) >
                        window.getSize().y && increment.y > 0) ||
                        (mushroom.getPosition().y - (size.y / 2) < 0 &&
                                increment.y < 0))
       
                {// Reverse the direction on Y axis.
                        increment.y = -increment.y;
                }

               
                mushroom.setPosition(mushroom.getPosition() + increment);
                window.clear(sf::Color(16, 16, 16, 255)); // Dark gray.
                window.draw(mushroom); // Drawing our sprite.
                window.display();
        }
       
}


       
       
       
       

       

 

Programmy

  • Newbie
  • *
  • Posts: 19
    • View Profile
oh nevermind I fixed it.....I made a time object beforehand, how silly of me