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 - Felshire

Pages: [1]
1
General / How to get real mouse coordinates
« on: February 18, 2012, 09:20:49 am »
NVM

TOOK ME 4 HOURS

But I finally got it

Might want to update document because it says nothing about event MouseButton

2
General / How to get real mouse coordinates
« on: February 18, 2012, 07:58:52 am »
How do you get the real mouse coordinates??

I know how to get the mouse coordinates relative to the window, but I need the coordinates from the (0,0) point of the actual game. (Not window)

Ive been trying for like 3 hours

:C

3
General / How to get FPS in SFML 2
« on: February 12, 2012, 01:18:37 pm »
Quote from: "Laurent"
Quote
But how am i supposed to convert a float to a string

The same way you convert an int to a string.

Quote
That code doesnt produce any meaningful results....

I wrote it quickly without testing, but in case there's an error you should be able to correct it, I think you get the idea.


unfortunately i dont ;_;

toying around and cant get it without using my first method

4
General / How to get FPS in SFML 2
« on: February 12, 2012, 10:38:29 am »
Quote from: "Laurent"
Why is it such a problem? FPS should only be used to have a rough estimate of the performances, it doesn't have to be accurate.

You can try this way:
Code: [Select]
int main()
{
    sf::RenderWindow Window(sf::VideoMode(1024, 768, 32), "Test");

    sf::Clock clock;
    float lastTime = 0;
    while (Window.IsOpen())
    {
            ...
            float currentTime = clock.Restart().AsSeconds();
            float fps = 1.f / (currentTime - lastTime);
            lastTime = currentTime;
    }

    return 0;
}

It won't be 100% accurate because frame times are tiny, but at least the error won't accumulate over time.


Also,
That code doesnt produce any meaningful results....

Its just random numbers if you print them out

5
General / How to get FPS in SFML 2
« on: February 12, 2012, 10:07:15 am »
Quote from: "Laurent"
Why is it such a problem? FPS should only be used to have a rough estimate of the performances, it doesn't have to be accurate.

You can try this way:
Code: [Select]
int main()
{
    sf::RenderWindow Window(sf::VideoMode(1024, 768, 32), "Test");

    sf::Clock clock;
    float lastTime = 0;
    while (Window.IsOpen())
    {
            ...
            float currentTime = clock.Restart().AsSeconds();
            float fps = 1.f / (currentTime - lastTime);
            lastTime = currentTime;
    }

    return 0;
}

It won't be 100% accurate because frame times are tiny, but at least the error won't accumulate over time.


Didnt know you could do that "clock.Restart().AsSeconds();" thing. Thanks.

But how am i supposed to convert a float to a string that I can print out with Window.Draw()?

6
General / How to get FPS in SFML 2
« on: February 12, 2012, 09:46:56 am »
Hers what I have so far:
Code: [Select]

#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
#include <string>
sf::Time thetime;
sf::Clock elapsed;

std::string IntToString(int d)
{
   std::stringstream ss;
   ss << d;
   return ss.str();
}

std::string GetFrameRate()
{    static int frameCounter = 0;
      static int fps = 0;
      frameCounter++;
      thetime = elapsed.GetElapsedTime();
      if(thetime.AsMilliseconds() > 999)
      {
         fps = frameCounter;
         frameCounter = 0;
         elapsed.Restart();
      }

      return IntToString(fps);
}

int main()
{
    sf::RenderWindow Window(sf::VideoMode(1024, 768, 32), "Test");
    Window.EnableVerticalSync(true);

    sf::Text FPS("0", sf::Font::GetDefaultFont(), 25);


    while (Window.IsOpen())
    {
            Window.Clear();
            FPS.SetString(GetFrameRate());
            Window.Draw(FPS);
            Window.Display();
        }

    return 0;
}


The problem with my code is that its not exactly frames per second.
Its always slightly higher than 1000 milliseconds and would probably be much higher if I were to draw more things in the loop.

So what do I change here?

Pages: [1]
anything