I've been hard at work trying to learn different functions and such. For some odd reason my computer is running this demonstration at around 45 frames per second according to FRAPs. Now, I'm using Visual C++ 2010 in debug mode. I watched the installation video on Youtube to recompile the 2008 files.
I have several beginners questions.
1. How do I create a release version of a program with SFML? Currently I just use the -s-d extensions as shown in the video.
2. Any ideas why this runs at 45 frames per second when I have locked it to 60? (Windows XP Service pack 3, 2 GB RAM, AMD Athlon 64 processor.)
3. Please let me know any bad habits I have started here while trying to teach myself this library.
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
class Player
{
public:
//positions
int x;
int y;
// for grabbing parent window events
sf::RenderWindow * parent_window;
Player(int start_x, int start_y, sf::RenderWindow * window)
{
x = start_x;
y = start_y;
parent_window = window;
}
void update()
{
// move the player in the window
const sf::Input& input = parent_window->GetInput();
// use the sums of the key directions to figure out movement
x -= (input.IsKeyDown(sf::Key::Left)-input.IsKeyDown(sf::Key::Right)) * 8;
y -= (input.IsKeyDown(sf::Key::Up)-input.IsKeyDown(sf::Key::Down)) * 8;
sf::Shape my_shape = sf::Shape::Circle(x,y, 16, sf::Color(255,0,255));
parent_window->Draw(my_shape);
}
~Player(){};
};
int main()
{
sf::RenderWindow main_window(sf::VideoMode(800, 600, 32), "Demo");
main_window.SetFramerateLimit(60);
main_window.UseVerticalSync(true);
Player the_player(400,300,&main_window);
while(main_window.IsOpened())
{
main_window.Clear();
sf::Event main_window_event;
// Process events
while (main_window.GetEvent(main_window_event))
{
// Close window : exit
if (main_window_event.Type == sf::Event::Closed)
{
main_window.Close();
}
}
// update the player
the_player.update();
// Display window contents on screen
main_window.Display();
}
return 0;
}